fluidwait<webdriver> 类型中的 withtimeout(duration)

使用此代码时出现错误,错误是

“FluentWait 类型中的方法 withTimeout(Duration) 不适用于参数 (int, TimeUnit)”

Wait wait = new FluentWait(driver)    
    .withTimeout(30, SECONDS)    
    .pollingEvery(5, SECONDS)   
    .ignoring(NoSuchElementException.class);


倚天杖
浏览 130回答 3
3回答

慕沐林林

这是现在正确的用法..Wait&nbsp;wait&nbsp;=&nbsp;new&nbsp;FluentWait(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofSeconds(30)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.ignoring(NoSuchElementException.class);

绝地无双

我搜索了以下代码对我有用&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wait<WebDriver>&nbsp;wait&nbsp;=&nbsp;new&nbsp;FluentWait<WebDriver>(driver) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.withTimeout(10,&nbsp;TimeUnit.SECONDS) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.pollingEvery(2,&nbsp;TimeUnit.SECONDS) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.ignoring(NoSuchElementException.class);

暮色呼如

在满足一个条件后,变量名称应该是任何东西而不是“wait”,即“wait1”可以工作#完整等待代码@SuppressWarnings("unchecked")Wait **wait1** = new FluentWait(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofSeconds(30)).ignoring(NoSuchElementException.class);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;@SuppressWarnings("unchecked")WebElement element = (WebElement) wait1.until(new Function<WebDriver, WebElement>() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public WebElement apply(WebDriver arg0) {WebElement linkelement = driver.findElement(By.cssSelector("button[class='btn btn-primary']"));if (linkelement.isEnabled()) {&nbsp; &nbsp; &nbsp; System.out.println("Element is Found");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;return linkelement;&nbsp; &nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java