我是selenium webdriver的新手。任何人都可以帮我在我的剧本中使用fluentwait
吗?
这是我的HTML代码:
<ul id="ui-id-6" class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content" tabindex="0" style="display: block; width: 827px; top: 405px; left: 374px;">
答案 0 :(得分:1)
试试这个:
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("ul#ui-id-6"))));
答案 1 :(得分:0)
通过使用Fluent等待,它等待直到找到元素。如果找不到该元素,则每5秒重试一次,但最多只能等待30秒。
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
答案 2 :(得分:0)
在try / catch块中使用WebDriver等,
WebDriverWait wait = new WebDriverWait(driver, timeout);
WebElement ele = null;
try {
ele = wait.until(ExpectedConditions
.presenceOfElementLocated(locator));
} catch (Exception e) {
throw e;
}
还需要传递超时。 有关处理内部和外部等待的更多信息请遵循this回答。 :)