如何在点击按钮后等待页面变暗(加载)?我尝试了以下选项但尚未成功。我必须捕获交易时间。
1)隐含等待
(driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);)
2)明确等待
(wait = new WebDriverWait(driver, 200);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//a[@ardbn='z3Btn_TDS_Next']/div/img)[position()<3]")));)
3)我自己的一个功能
public void waitForPageLoaded() {
ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete"); } };
Wait<WebDriver> wait = new WebDriverWait(driver,30); try { wait.until(expectation); } catch(Throwable error) { fail("Timeout waiting for Page Load Request to complete."); } }
答案 0 :(得分:2)
等到加载框不可见。 假设加载框的locator / id / xpath是id = loader,那么
By locator = By.id("loader");
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(timeOutInSeconds, TimeUnit.SECONDS)
.pollingEvery(pollingIntervalInSeconds, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));