标签:app out code span highlight tin find until for
智能等待,并忽略NoSuchElementException异常
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 500 millisSeconds.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofMillis(500))
.ignoring(NoSuchElementException.class);
//wait until the element is returned, the timeout is not returned and throws a TimeOutException
WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("foo"));
}
});
目的:设置在抛出错误之前等待页面加载完成的时间。如果超时为负,则页面加载可能是无限期的。
driver.manage().timeouts().pageLoadTimeout(100, SECONDS);
用途:设置在抛出错误之前等待异步脚本完成执行的时间。如果超时为负,则允许脚本无限期运行。
driver.manage().timeouts().setScriptTimeout(100,SECONDS);
标签:app out code span highlight tin find until for
原文地址:https://www.cnblogs.com/wldan/p/10544881.html