1、公司同事给了一个全局的等待处理,
中间的判断核心就是 通过js的脚本判断页面是否刷新完,状态是complete。如果是的话再执行以下的脚本,
否则等待系统的全局等待时间。
//等待页面加载时间 public static void waitForPage(WebDriver myDriver)throws Exception { ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return ((JavascriptExecutor) driver).executeScript( "return document.readyState").toString().equalsIgnoreCase("complete"); } }; Wait<WebDriver> wait = new WebDriverWait(myDriver, 30);//这里的驱动 是系统的驱动 方法里面传进来的驱动 try { wait.until(expectation); } catch (Exception e) { System.out.println("Timeout waiting for Page Load Request to complete."); } //System.out.println("before sync: " + Global.getDriver().executeScript("return document.readyState").toString()); //Thread.sleep(5000); //System.out.println("after sync: " + Global.getDriver().executeScript("return document.readyState").toString()); Thread.sleep(500); }
时间: 2024-10-16 02:10:54