WebDriver - 等到元素不可见 [英] WebDriver - wait until invisibility of element

查看:54
本文介绍了WebDriver - 等到元素不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面页面工厂中定义了元素

i have element defined in page page factory

@FindBy(xpath = "//*[contains(@style,'gxt/images/default/tree/loading.gif')]")
WebElement treeLoading;

我想等待这个元素消失,而 ExpectedConditions 不支持 invisiblityOfElementLocated(WebElement),有没有更好的方法来编写自定义等待?

i would like to wait for this element to disappear and ExpectedConditions does not support invisiblityOfElementLocated(WebElement), is there any better approach to write custom wait?

推荐答案

所以,最后我使用 fluent wait 得到了以下解决方案

so, finally i came with following solution using fluent wait

protected void waitUntilElementDisappear(final WebElement element){
        try{
              new FluentWait<WebDriver>(driver)
              .withTimeout(10,TimeUnit.SECONDS)
              .pollingEvery(10,TimeUnit.SECONDS)
              .ignoring(NoSuchElementException.class)
              .until(new ExpectedCondition<Boolean>(){
                public Boolean apply(WebDriver driver){
                    return (!element.isDisplayed());                             
                }
              }
            );
        }catch(TimeoutException e){
            fail("Time Out On : "+element);
        }
    }

这篇关于WebDriver - 等到元素不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆