如何声明WebDriver超时以及如何管理其优先级



对于我在代码的早期设置的网络驱动程序

driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);

然后稍后我申报类似的东西

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(bla bla

new WebDriverWait(driver, 5).until(bla bla

它似乎没有效果,因为它等待的时间比5秒更长

这些暂停的规则是什么?

您应该永远不要将隐式等待与显式等待混合
这意味着,如果为implicitlyWait定义了非默认值,则不应在该驱动程序会话中使用WebDriverWait
请参阅官方建议中的Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds could cause a timeout to occur after 20 seconds
通常我们总是使用WebDriverWait显式等待,只将implicitlyWait设置为默认值0
您可以在此处和更多类似的讨论中看到更多解释。

最新更新