Selenium FluentWait 方法未能忽略 NoSuchElement [英] Selenium FluentWait method failing to ignore NoSuchElement

查看:27
本文介绍了Selenium FluentWait 方法未能忽略 NoSuchElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络报告页面,我必须在其中验证每个页面中的所有日期字段.我可以访问每个页面并进行验证,但我的脚本在 FluentWait 方法中出现错误

I have a web report page where I have to verify all the date fields in each page. I can get to each page and do the verification but my script gives an error at the FluentWait method

我必须获取第一页的日期,进行验证,然后单击下一步"按钮(如果已启用).如果未启用,我将退出循环.

I have to get the dates of first page, verify it and then click the Next button if its enabled. If its not enabled I get out of the loop.

do {

......
.....
FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(500, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class);

    fluentWait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00"))));
    driver.findElement(By.id("ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00")).click();


} while (driver.findElement(By.id("ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00")).isEnabled());

但是我得到一个错误.为什么 NoSuchElement 覆盖不起作用?如何优雅地退出 ExpectedConditions.elementToBeClickable?

But I get an error. Why is the NoSuchElement override not working? How can I exit from ExpectedConditions.elementToBeClickable gracefully?

有没有更好的方法来做到这一点?

Is there a better way to do this?

org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for element to be clickable: [[FirefoxDriver: firefox on XP (256df980-a068-474c-9469-2ff4e8e13b3e)] -> id: ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00]
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'PC-L-JOSU', ip: '172.26.70.109', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_40'
Driver info: driver.version: unknown
org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for element to be clickable: [[FirefoxDriver: firefox on XP (256df980-a068-474c-9469-2ff4e8e13b3e)] -> id: ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00]
 org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:259)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228)
at com.stta.ReportsParkingTransactions.ReportsParkingTransactions.ReportParkingTransactions(ReportsParkingTransactions.java:414)

谢谢

编辑

我在没有预期条件的情况下尝试并看到此错误.我错过了什么

I tried without the expected conditions and see this error. What am I missing

请有人帮忙!.. :-)... 我已经用谷歌搜索了这个并到处寻找可能的地方,但最近几天我被困住了!!!

Someone please help!.. :-)... I have googled this and looked everywhere posible and I'm stuck for the last few days !!!

推荐答案

尝试在忽略方法中添加 'TimeoutException.class',它也会忽略超时异常.所以测试用例不会因为超时异常而失败.

Try adding 'TimeoutException.class' in ignoring method which will ignore timeout exception as well. So test case will not fail for timeout exception.

EX:.ignoring(NoSuchElementException.class, TimeoutException.class)

这篇关于Selenium FluentWait 方法未能忽略 NoSuchElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆