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