When I use WebDriverWait rather than Thread.sleep I get a StaleElementReferenceException

后端 未结 2 1598
心在旅途
心在旅途 2021-01-29 10:10

I am trying to write a Selenium object Builder for a Swagger page, in groovy. For the purposes of this discussion, my problem code can be reduced down to the following:

2条回答
  •  无人及你
    2021-01-29 10:23

    After the most excellent research / suggestion by @Louis, I ended up using:

    def wait = new FluentWait(By.className("resource")).
            withTimeout(10, TimeUnit.SECONDS).
            ignoring(NoSuchElementException)
    wait.until(new Function() {
                WebElement res
                Boolean apply(By by) {
                    def oldRes = res
                    res = driver.findElement(by)
                    return res == oldRes
                }
            })
    

    If anyone is interested, the entire Builder can be found on SourceForge (still under construction at the time of this writing).

提交回复
热议问题