c# – Selenium Wait不等待Element可点击
发布时间:2020-12-15 22:17:22 所属栏目:百科 来源:网络整理
导读:我有一个动态加载的页面,包含一个按钮.我正在尝试等待按钮可以使用C#绑定点击selenium.我有以下代码: WebDriverWait wait = new WebDriverWait(Driver.Instance,TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("add
我有一个动态加载的页面,包含一个按钮.我正在尝试等待按钮可以使用C#绑定点击selenium.我有以下代码:
WebDriverWait wait = new WebDriverWait(Driver.Instance,TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("addInspectionButton"))); var button = Driver.Instance.FindElement(By.Id("addInspectionButton")); button.Click(); 这不起作用. click事件永远不会被触发. selenium脚本不会抛出异常,提示ID为“addInspectionButton”的元素不存在.它只是无法点击它.如果我添加一个Thread.Sleep(3000)在wait语句和我得到按钮元素句柄的行之间它可以工作. 我在这里没有正确使用ExpectedConditions.ElementToBeClickable吗? 解决方法
事实证明,在将按钮动态添加到页面后,事件被绑定到按钮.所以按钮被点击但没有发生任何事情.放置在代码中的睡眠线程只是给客户端事件时间绑定.
我的解决方案是单击按钮,检查预期结果,然后重复,如果预期结果尚未在DOM中. 由于预期的结果是打开一个表单,我像这样轮询DOM: button.Click();//click button to make form open var forms = Driver.Instance.FindElements(By.Id("inspectionDetailsForm"));//query the DOM for the form var times = 0;//keep tabs on how many times button has been clicked while(forms.Count < 1 && times < 100)//if the form hasn't loaded yet reclick the button and check for the form in the DOM,only try 100 times { button.Click();//reclick the button forms = Driver.Instance.FindElements(By.Id("inspectionDetailsForm"));//requery the DOM for the form times++;// keep track of times clicked } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- XML自定义检查器语法+约束(1)
- ruby-on-rails – 在RoR中重定向:使用redirect_
- Oracle认证专家视频教程-OCP全套教程之学习笔记-
- ios – 将CIImage转换为CGImage太慢了
- Flex 3 与 Flex 4 之间的区别
- c# – 如何激发对共享资源的同时访问?
- flash – 如何在Youtube视频(z-index)上显示div?
- c – Visual Studio 2010的替代unistd.h头文件
- Oracle 11g ORA-00314、ORA-00312 redo日志与控制
- c – Boost.Multiprecision cpp_int – 转换成字
热点阅读