我不确定等待 favicon 是否是个好主意。不同的应用程序使用不同的技术,而且IMO 不可能有一个通用的等待可以适用于所有 Web 应用程序。以下是我用于“我的”应用程序的内容。这给了你一个想法。您需要构建适合“您的”应用程序的内容。
public void my_generic_wait_for_page_load() {
final WebDriverWait wait = new WebDriverWait(this.getDriver(), 300);
final JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
final ExpectedCondition<Boolean> jQueryActive_toBeZero = new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
try {
return ((Long) jsExecutor
.executeScript("return jQuery.active") == 0) ? true
: false;
} catch (final WebDriverException e) {
log.warn("It looks like jQuery is not available on the page, skipping the jQuery wait, check stack trace for details",e);
return true; //skip the wait
}
}
};
final ExpectedCondition<Boolean> document_readyState_toBeComplete = new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
return jsExecutor.executeScript("return document.readyState")
.toString().equals("complete") ? true : false;
}
};
wait.until(jQueryActive_toBeZero);
wait.until(document_readyState_toBeComplete);
}