Selenium(Webdriver)显式等待封装

xiaoxiao2021-02-28  110

// 显示等待页面元素出现的封装方法,参数为页面元素的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; }
转载请注明原文地址: https://www.6miu.com/read-23535.html

最新回复(0)