2013-04-26 98 views
1

我想等我的线程,直到元素不存在或隐藏。这样等到元素未找到或隐藏

new WebDriverWait(driver, TIME_OUT_SECS).until(new ExpectedCondition<WebElement>() { 
       @Override 
       public Boolean apply(WebDriver d) { 
        return !d.findElement(by).isDisplayed(); 
       } 
      }); 

,但得到的错误

attempting to use incompatible return type 

回答

1

可能只是一个自动装箱无法尝试的代码 - 你试图改变

return !d.findElement(by).isDisplayed(); 

return (Boolean)!d.findElement(by).isDisplayed(); 

?正如显示返回boolean,但你实际上需要Boolean应该被自动装箱,但关于自动装箱你永远不知道。

1

看来,您使用的是ExpectedCondition打字错误的位置:

new ExpectedCondition<WebElement>() 

这应该创建一个类的方法

public WebElement apply(WebDriver arg0) {} 

正如你所看到的,预期收益类型apply()是传入类型参数的类。

你可能想要做的:

new ExpectedCondition<Boolean>()