使用此代码时出现错误,错误是
"类型为 FluentWait 的带有 Timeout(Duration( 的方法不是 适用于参数(整数,时间单位(">
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
这是现在的正确用法。
Wait wait = new FluentWait(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofSeconds(30))
.ignoring(NoSuchElementException.class);
我搜索了一下,以下代码对我有用
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(10, TimeUnit.SECONDS)
.pollingEvery(2, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
在一个条件下工作之后,变量名应该是任何东西而不是"等待",即"wait1"将起作用
#CompleteWaitCode
@SuppressWarnings("unchecked")
Wait **wait1** = new FluentWait(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofSeconds(30)).ignoring(NoSuchElementException.class);
@SuppressWarnings("unchecked")
WebElement element = (WebElement) wait1.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver arg0) {
WebElement linkelement = driver.findElement(By.cssSelector("button[class='btn btn-primary']"));
if (linkelement.isEnabled()) {
System.out.println("Element is Found");
}
return linkelement;
}
});