![WebDriver 页面等待 WebDriver 页面等待](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
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);
}