正确的等待等待元素消失?
我有一个ajax加载程序,例如单击按钮后加载,我的方法是否正确,以便等待一个特定的加载栏,该加载栏需要屏幕的整个宽度和高度消失?
public void waitUntilAjaxLoaderDisapears() {
// Wait up to 2minutes for the element to disappear
WebDriverWait ajaxWait = new WebDriverWait(this.driver, 60);
ajaxWait.pollingEvery(100, TimeUnit.SECONDS);
try {
//tempWait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".modal-body")));
ajaxWait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[contains(@class, 'ajax_loader')]")));
} catch (UnhandledAlertException e) {
Alert alert = driver.switchTo().alert();
alert.accept();
}catch (NoAlertPresentException e) {
//
}catch (StaleElementReferenceException e) {
// do nothing
} catch (NullPointerException e) {
// do nothing
} catch (Exception e) {
// do nothing
}
}
最佳答案
我想我遇到了这个问题。轮询时间应小于总等待时间。原来如此,
WebDriverWait ajaxWait = new WebDriverWait(this.driver, 60);
ajaxWait.pollingEvery(**5**, TimeUnit.SECONDS);
而不是
WebDriverWait ajaxWait = new WebDriverWait(this.driver, 60);
ajaxWait.pollingEvery(100, TimeUnit.SECONDS);
希望这对您有帮助。谢谢。
关于java - 正确的等待等待元素消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44326893/