我确实有一个等待 JavaScript 在浏览器中加载的方法。从 Selenium 3 (3.141.59),我已经转移到 Selenium 4 (4.0.0-alpha-7)
此返回代码/语句不适用于 Selenium 4
return wait.until(jQueryLoad) && wait.until(jsLoad);
什么是正确的返回声明?我尝试了几种选择,但没有任何效果。请参阅下面的方法/功能的代码结构。您的想法、想法和答案将受到高度评价。
public static boolean waitForJStoLoad() {
WebDriverWait wait = new WebDriverWait(getDriver(), Duration.ofSeconds(30));
// wait for jQuery to load
ExpectedCondition<Boolean> jQueryLoad = new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver arg0) {
try {
Long state = (Long) ((JavascriptExecutor) arg0).executeScript("return jQuery.active");
return (state == 0);
} catch (Exception e) {
return true;
}
}
};
// wait for Javascript to load
ExpectedCondition<Boolean> jsLoad = new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver arg0) {
String state = (String) ((JavascriptExecutor) arg0).executeScript("return document.readyState;");
return state.equalsIgnoreCase("complete");
}
};
return wait.until(jQueryLoad) && wait.until(jsLoad);
}