WebDriverWait 在 Selenium 4 中被弃用

新手上路,请多包涵

我得到一个

警告:(143,13) ‘WebDriverWait(org.openqa.selenium.WebDriver, long)’ 已弃用

在硒 4.0.0-alpha-3 中。

但官方 Selenium 页面 仅列出

WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds, long sleepTimeOut)

作为弃用。

怎么了?我正在使用 IntelliJ,这可能是他们的问题吗?

原文由 Mate Mrše 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.4k
2 个回答

它没有出现在文档中,但是如果您查看 源代码,您会看到 @Deprecated 注释

@Deprecated
public WebDriverWait(WebDriver driver, long timeoutInSeconds) {
    this(driver, Duration.ofSeconds(timeoutInSeconds));
}

在构造函数描述中,您有解决方案

@deprecated 相反,使用 {@link WebDriverWait#WebDriverWait(WebDriver, Duration)}。

在任何情况下,哪个是从已弃用的构造函数中调用的构造函数。

 new WebDriverWait(driver, Duration.ofSeconds(10));

原文由 Guy 发布,翻译遵循 CC BY-SA 4.0 许可协议

用 Selenium 4 这样写,因为正如您所说,您尝试使用的内容已被弃用。

先导入。

 import java.time.Duration;

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(30));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(60));

对于流利的等待。

  Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
        .withTimeout(Duration.ofSeconds(30))
        .pollingEvery(Duration.ofSeconds(5))
        .ignoring(NoSuchElementException.class);

WebDriverWait 语句

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));

原文由 Sameera De Silva 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题