selenium2.4.0版本提供了页面等待处理。
显示等待元素可见:
protected void WaitElementVisible(By by,int timeOutInSeconds,
long pollingInterval) {
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
wait.withMessage(String.format("Timeout waiting for element: %s", locator));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}
隐式等待:
protected void Waitfor(By by,int timeOutInSeconds,
long pollingInterval) {
driver.manage().timeouts().implicitlyWait(timeOutInSeconds, TimeUnit.SECONDS);
}