selenium经过WebDriverWait实现ajax测试
www.MyException.Cn 网友分享于:2013-09-12 浏览:217次
selenium通过WebDriverWait实现ajax测试
AndroidDriver driver = new AndroidDriver();
driver.get("http://m.taobao.com");
WebElement inputBox = driver.findElement(By.id("J_SKey"));
inputBox.sendKeys("1");
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;
}
});
assertTrue(driver.findElement(By.xpath("//div[@class='suggest']//li")).getText().contains("1"));
WebDriverWait(driver, 10)10秒内每隔500毫秒扫描1次页面变化,当出现指定的元素后结束。