流利的等待

每個 FluentWait 例項定義等待條件的最大時間量,以及檢查條件的頻率。此外,使用者可以將等待配置為在等待時忽略特定型別的異常,例如在搜尋頁面上的元素時的 NoSuchElementExceptions。它與驅動程式相關聯。

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS) //actuall wait for the element to pe present
.pollingEvery(5, SECONDS) //selenium will keep looking for the element after every 5seconds
.ignoring(NoSuchElementException.class); //while ignoring this condition
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("username"));