使用webdriver並測試使用gwt構建的應用程序。我想先聲明一個元素成爲現在。這個元素是動態加載的,並不是微不足道的測試。不過,我需要斷言元素不再存在。就像在它不再存在的那樣。我最初的做法是構建ExpectedCondition,然後等待條件,即 斷言元素不再存在
ExpectedCondition<Boolean> e = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.findElements(By.cssSelector(someCSSpath)).size() == 0;
}};
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(e);
I would have expected that would have waited for 15 seconds for the element to disappear from the dom, I would expected that it would poll every 500 milis. I would expect that at every poll the bool would be false as the element would be found until such time as it disappears and at which point the condition becomes true. What I find in my output is that indeed it polls every 500 milis however once the condition becomes true I actually wait for an entire minute before moving onto the next step. This seems incorrect behavior, am I missing something? Any suggestions?
每該文檔[JavaDoc的用於WebDriverWait](http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html)這個特定的構造函數有2個參數,所述第二一個是很長的,在幾秒鐘內。 – Kilthorn 2012-01-17 16:23:35
你是否指定了隱式等待?如果是的話,你可能需要關閉這個條件,因爲findElements()會等待(在隱式等待期間)元素至少存在一次。 – 2012-04-09 23:40:41