等待价格完全加载的最佳方式(例如在比较网站上)
Best way to wait until prices load completely (such as on comparision websites)
我尝试使用隐式等待,但不知何故它不起作用,然后我也尝试了显式等待,例如 sleep
,但它再次不起作用,也不是一个好的做法。
然后我查看了 fluent wait,但是因为我使用的是 PageFactory
并且旧版本的 fluent wait 已被弃用,有谁知道我如何与 PageFactory
.
一起实现 fluent wait
给你...
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();
}
}
我尝试使用隐式等待,但不知何故它不起作用,然后我也尝试了显式等待,例如 sleep
,但它再次不起作用,也不是一个好的做法。
然后我查看了 fluent wait,但是因为我使用的是 PageFactory
并且旧版本的 fluent wait 已被弃用,有谁知道我如何与 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();
}
}