java - 正确的等待等待元素消失?

标签 java selenium selenium-webdriver webdriver

正确的等待等待元素消失?

我有一个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/

相关文章:

javascript - 如何使用 selenium web 驱动程序在代码镜像中输入值?

java - Spring 数据/hibernate : Sort enum by it's field

java - 无法让 HTMLUnit 跟踪使用 __doPostBack() 函数的页面上的链接

java - 特定 url 格式的正则表达式

python - 进入新页面时, Selenium 会丢失 session

javascript - 将 javascript webdriver.Capabilities 转换为字符串

webdriver - 如果等待插槽空闲,Grid Hub http 客户端超时

Java Hibernate Projections.sqlGroupProjection 别名

testing - Selenium 2.0/网络驱动程序

selenium-webdriver - 如何防止数据提供者将登录凭据等敏感数据打印到控制台?