2013-04-26 53 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>()