我尝试使用隐式等待,但不知何故不起作用,然后我也尝试了显式等待,如sleep
,但同样不起作用。然后我查看了fluent wait,但因为我使用的是PageFactory
,而且旧版本的fluent waite已被弃用,有人知道我如何将fluent wai与PageFactory
一起实现吗。
给你。。。
public static void waitForElement(WebElement element){
try {
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofMillis(60000))
.pollingEvery(Duration.ofMillis(1000))
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
wait.until(ExpectedConditions.elementToBeClickable(element));
waiting(100);
//can add further action here
} catch (Exception e) {
e.printStackTrace();
}
}