Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium FluentWait方法未能忽略NoTouchElement_Java_Selenium_Webdriver - Fatal编程技术网

Java Selenium FluentWait方法未能忽略NoTouchElement

Java Selenium FluentWait方法未能忽略NoTouchElement,java,selenium,webdriver,Java,Selenium,Webdriver,我有一个web报告页面,我必须验证每个页面中的所有日期字段。我可以访问每个页面并进行验证,但我的脚本在FluentWait方法中给出了一个错误 我必须获得第一页的日期,验证它,然后单击“下一步”按钮(如果已启用)。如果未启用,我将退出循环 do { ...... ..... FluentWait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver) .withTimeout(30,

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

我必须获得第一页的日期,验证它,然后单击“下一步”按钮(如果已启用)。如果未启用,我将退出循环

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());
谢谢

编辑


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


有人来帮忙。:-)。。。我已经在谷歌上搜索过了,到处都找遍了,这几天我都被卡住了

我所能说的是,您不应该将
ExpectedConditions
FluentWait
一起使用,至少您不需要这样做。根据以下几点就足够了

// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
       .withTimeout(30, SECONDS)
       .pollingEvery(5, SECONDS)
       .ignoring(NoSuchElementException.class);

WebElement reportViewer = wait.until(new Function<WebDriver, WebElement>() {
  public WebElement apply(WebDriver driver) {
    return driver.findElement(By.id("ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00"));
  }
});

reportViewer .click();
//等待30秒,让元素出现在页面上,检查
//每5秒检查一次。
等待等待=新建FluentWait(驱动程序)
.带超时(30秒)
.每(5秒)轮询一次
.忽略(NoSuchElementException.class);
WebElement reportViewer=等待.until(新函数(){
公共WebElement应用(WebDriver){
返回driver.findElement(By.id(“ReportViewer1\u ctl06\u ctl00\u Next\u ctl00\u ctl00”);
}
});
reportViewer.click();

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


例如:忽略(NoSuchElementException.class,TimeoutException.class)

这可能是一个语法错误,比如缺少引号分号吗?不。。最初我也尝试过这个,当我遇到这个错误时,我尝试过按预期的条件执行。@user3749141我猜你错过了导入
import org.openqa.selenium.support.ui.Wait
你能提供完整的代码块,然后包括导入的
吗?我看不出在我的末尾它不允许我发布完整的代码,因为它显然太多了。我尝试了这个,但仍然得到相同的错误“30秒后超时”:(尝试使用'ignoreAll()'或'ignoreAll(Exception.class)'“.不走运..我仍然得到TimoutException…!!”ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00_ctl00“是否始终保持不变?我认为它可能是一个动态的idNo..它不是动态的,因为它每次都工作,只要按钮处于启用状态..我只有在状态变为禁用时才会出现此问题。”
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
       .withTimeout(30, SECONDS)
       .pollingEvery(5, SECONDS)
       .ignoring(NoSuchElementException.class);

WebElement reportViewer = wait.until(new Function<WebDriver, WebElement>() {
  public WebElement apply(WebDriver driver) {
    return driver.findElement(By.id("ReportViewer1_ctl06_ctl00_Next_ctl00_ctl00"));
  }
});

reportViewer .click();