WebDriverWait(driver, 10)10秒内每隔500毫秒扫描1次页面变化,当出现指定的元素后结束。
http://fox1984.iteye.com/blog/1225265
new WebDriverWait(driver, 10).until (new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
Boolean result = false;
try {
driver.findElement(By.xpath("//div[@class='suggest']//li"));
result = true;
} catch(Exception e){
}
return result;
}
});
----------------------------------------------------------------------
https://github.com/easonhan007/webdriver_guide/blob/master/18/modal.java.md
// 打开对话框
dr.findElement(By.id("show_modal")).click();
(new WebDriverWait(dr, 10)).until(
new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.findElement(By.id("myModal")).isDisplayed();
}
}
);
// 点击对话框中的链接
// 由于对话框中的元素被蒙板所遮挡,直接点击会报 Element is not clickable的错误
// 所以使用js来模拟click
// 在watir-webdriver中只需要fire_event(:click)就可以了
WebElement link = dr.findElement(By.id("myModal")).findElement(By.id("click"));
((JavascriptExecutor)dr).executeScript("$(arguments[0]).click()", link);