简体   繁体   English

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

[英]Geb/Selenium - Other element would receive the click

I'm using a mixture of Geb and Selenium to do front end testing for our web portal. 我正在使用Geb和Selenium的混合物来为我们的门户网站进行前端测试。 Our former developers implemented an overlay div to block any access to page when waiting for content. 我们以前的开发人员实现了一个overlay div来阻止在等待内容时对页面的任何访问。 Thus, I often have to wait for this div to not being visible any longer before I can click on an element of interest. 因此,在点击感兴趣的元素之前,我经常不得不等待这个div不再可见。

I applied a fluent wait to check for overlay div not visible but sometimes the click goes to this overlay div anyway. 我应用了一个流畅的等待来检查叠加div是不可见的,但有时候点击会转到这个叠加div。 That's really strange: The overlay is not visible resp. 这真的很奇怪:覆盖层不可见。 not attached to the DOM tree but the click goes to it. 没有附加到DOM树,但点击进入它。

How can this happen? 怎么会发生这种情况? What can I do to work around this issue? 我该怎么做才能解决这个问题?

Replacing the fluent wait: 取代流利的等待:

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
}

by a loop suggested by Saifur: 通过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
    }
}

could solve my problem. 可以解决我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM