流利的等待
每个 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"));