最佳答案
public class CustomExpectedConditions {
public static ExpectedCondition pageStateToBeReady() {
return object -> (((JavascriptExecutor) getDriver()).executeScript("return document.readyState")).equals("complete");
}
}
public static void pageToBeLoaded() {
try {
new WebDriverWait(getDriver(), TIMEOUT).until(CustomExpectedConditions.pageStateToBeReady());
} catch (TimeoutException e) {
log.info(e.getMessage(), e.getCause());
throw new TimeOutError("Page is not loaded");
}
}
使用此代码片段。它将等待页面加载。之后,来自 API 的数据将可用。
关于java - 在selenium中,当HTML中不存在文本但来自api响应时,我们可以从网页中检索文本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58949333/