// 显示等待页面元素出现的封装方法,参数为页面元素的By对象
public static WebElement waitWebElement(WebDriver driver, final By by, int second) {
WebElement waitElement = null;
WebDriverWait wait = new WebDriverWait(driver, second);
try {
// 创建一个新的ExpectedCondition接口,实现apply方法
waitElement = wait.until(new ExpectedCondition<WebElement>(){
public WebElement apply(WebDriver d) {
return d.findElement(by);
}
});
} catch (Exception e) {
System.out.println(by.toString() + " is not exist until " + second);
}
return waitElement;
}
Selenium(Webdriver)显式等待封装
最新推荐文章于 2023-09-05 15:09:44 发布