首页 文章

Geb / Selenium - 其他元素会收到点击

提问于
浏览
0

我正在使用Geb和Selenium的混合物来为我们的门户网站进行前端测试 . 我们以前的开发人员实现了一个overlay div来阻止在等待内容时对页面的任何访问 . 因此,在点击感兴趣的元素之前,我经常不得不等待这个div不再可见 .

我应用了一个流畅的等待来检查叠加div是不可见的,但有时候点击会转到这个叠加div . 这真的很奇怪:覆盖层不可见 . 没有附加到DOM树,但点击进入它 .

怎么会发生这种情况?我该怎么做才能解决这个问题?

1 回答

  • 0

    取代流利的等待:

    protected final boolean waitForPageNotBusy(By by = By.className("busyOverlay")) {
        log.debug("Waiting for page not busy...")
        def timeout = 120
        boolean isNotBusy = new FluentWait(driver)
            .withMessage("Busy overlay still visible after $timeout seconds.")
            .pollingEvery(1, TimeUnit.SECONDS)
            .withTimeout(timeout, TimeUnit.SECONDS)
            .ignoring(org.openqa.selenium.NoSuchElementException.class)
            .ignoring(UnhandledAlertException.class)
            .until(ExpectedConditions.invisibilityOfElementLocated(by) as Function);
        isNotBusy
    }
    

    通过Saifur建议的循环:

    protected final boolean waitForPageNotBusy() {
        By by = By.className("busyOverlay")
        log.debug("Waiting for element to disappear: {}", by.toString())
        try {
            while (driver.findElements(by).size() > 0) {
                log.debug("Element still visible: {}", by.toString())
                sleep(1000)
            }
        } catch (NoSuchElementException nse) {
            log.debug(nse.message)
            return true
        }
    }
    

    可以解决我的问题 .

相关问题