Selenium:元素等待(转)

显示等待,推荐使用显示等待

WebDriverWait wait = new WebDriverWait(dr, 10);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("kw")));

显式等待 使用ExpectedConditions类中自带方法, 可以进行显试等待的判断。 

显式等待可以自定义等待的条件,用于更加复杂的页面等待条件

(1)页面元素是否在页面上可用和可被单击:elementToBeClickable(By locator)

(2)页面元素处于被选中状态:elementToBeSelected(WebElement element)

(3)页面元素在页面中存在:presenceOfElementLocated(By locator)

(4)在页面元素中是否包含特定的文本:textToBePresentInElement(By locator)

(5)页面元素值:textToBePresentInElementValue(By locator, java.lang.String text)

(6)标题 (title):titleContains(java.lang.String title)

只有满足显式等待的条件满足,测试代码才会继续向后执行后续的测试逻辑

如果超过设定的最大显式等待时间阈值, 这测试程序会抛出异常。 

WebDriverWait wait = new WebDriverWait(driver,5); 

wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(""))); 

猜你喜欢

转载自www.cnblogs.com/AIME/p/11982186.html