10

我得到一个

警告:(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,这可能是他们的问题吗?

4

6 回答 6

16

它没有出现在文档中,但是如果您查看源代码,您会看到@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));
于 2019-12-04T05:38:18.807 回答
10

正如你所说,因为你试图使用的东西已被弃用,所以用 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));
于 2021-10-22T16:43:51.920 回答
6
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

改用这个,只支持 WebDriverWait(driver, clock);

于 2020-04-08T14:10:03.633 回答
3

此警告消息...

Warning: (143,13) 'WebDriverWait(org.openqa.selenium.WebDriver, long)' is deprecated

...意味着WebDriverWait的当前构造函数已被弃用。


查看WebDriverWait.java的代码似乎:

  • 不推荐使用以下方法:

    • public WebDriverWait(WebDriver driver, long timeoutInSeconds)

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

      @Deprecated
      public WebDriverWait(WebDriver driver, long timeoutInSeconds, long sleepInMillis) {
        this(driver, Duration.ofSeconds(timeoutInSeconds), Duration.ofMillis(sleepInMillis));
      }
      
    • public WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeoutInSeconds, long sleepInMillis)

      @Deprecated
      public WebDriverWait(
          WebDriver driver, Clock clock, Sleeper sleeper, long timeoutInSeconds, long sleepInMillis) {
        this(
            driver,
            Duration.ofSeconds(timeoutInSeconds),
            Duration.ofMillis(sleepInMillis),
            clock,
            sleeper);
      }
      
  • 虽然添加了以下方法:

    • public WebDriverWait(WebDriver driver, Duration timeout)

      /**
       * @param driver The WebDriver instance to pass to the expected conditions
       * @param timeout The timeout when an expectation is called
       * @see WebDriverWait#ignoring(java.lang.Class)
       */
      public WebDriverWait(WebDriver driver, Duration timeout) {
        this(
            driver,
            timeout,
            Duration.ofMillis(DEFAULT_SLEEP_TIMEOUT),
            Clock.systemDefaultZone(),
            Sleeper.SYSTEM_SLEEPER);
      } 
      
    • public WebDriverWait(WebDriver driver, Duration timeout, Duration sleep)

      /**
       * Wait will ignore instances of NotFoundException that are encountered (thrown) by default in
       * the 'until' condition, and immediately propagate all others.  You can add more to the ignore
       * list by calling ignoring(exceptions to add).
       *
       * @param driver The WebDriver instance to pass to the expected conditions
       * @param timeout The timeout in seconds when an expectation is called
       * @param sleep The duration in milliseconds to sleep between polls.
       * @see WebDriverWait#ignoring(java.lang.Class)
       */ 
      public WebDriverWait(WebDriver driver, Duration timeout, Duration sleep) {
        this(driver, timeout, sleep, Clock.systemDefaultZone(), Sleeper.SYSTEM_SLEEPER);
      }
      
    • WebDriver driver, Duration timeout, Duration sleep, Clock clock, Sleeper sleeper)

      /**
       * @param driver the WebDriver instance to pass to the expected conditions
       * @param clock used when measuring the timeout
       * @param sleeper used to make the current thread go to sleep
       * @param timeout the timeout when an expectation is called
       * @param sleep the timeout used whilst sleeping
       */
      public WebDriverWait(WebDriver driver, Duration timeout, Duration sleep, Clock clock, Sleeper sleeper) {
        super(driver, clock, sleeper);
        withTimeout(timeout);
        pollingEvery(sleep);
        ignoring(NotFoundException.class);
        this.driver = driver;
      }
      

因此,您会看到错误。


但是,我没有看到Selenium v​​4.0.0-alpha*WebDriverWait Java 客户端更改日志中的Class 有任何更改,并且该功能应继续按照当前实现运行。

Selenium Java 客户端v4.0.0-alpha-3更新日志:

v4.0.0-alpha-3
==============

* Add "relative" locators. The entry point is through the `RelativeLocator`.
  Usage is like `driver.findElements(withTagName("p").above(lowest));`
* Add chromedriver cast APIs to remote server (#7282)
* `By` is now serializable over JSON.
* Add ApplicationCache, Fetch, Network, Performance, Profiler,
  ResourceTiming, Security and Target CDP domains.
* Fixing Safari initialization code to be able to use Safari Technology
  Preview.
* Ensure that the protocol converter handles the new session responses
  properly.
* Expose devtools APIs from chromium derived drivers.
* Expose presence of devtools support on a role-based interface
* Move to new Grid, deleting the old standalone server and grid implementation.
* Switch to using `HttpHandler` where possible. This will impact projects that
  are extending Selenium Grid.
* Respect "webdriver.firefox.logfile" system property in legacy Firefox driver.
  Fixes #6649
* Back out OpenCensus support: OpenTracing and OpenCensus are merging, so
  settle on one for now.
* Only allow CORS when using a —allow-cors flag in the Grid server
* If you're using the Java Platform Module System, all modules
  associated with the project are generated as "open" modules. This
  will change in a future release.
* The version of Jetty being used is unshadowed.

结论

Selenium 的 Java 客户端 v4.0.0-alpha-3仍然是一个alpha版本,需要通过beta版本,因此不应该用于生产环境中的测试活动。


解决方案

一个直接的解决方案是降级到当前发布的级别 版本 3.141.59

于 2019-11-22T12:09:33.217 回答
3

给出以下警告的代码:

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

警告:该类型
的方法已弃用。implicitlyWait(long, TimeUnit)WebDriver.Timeouts

在 selenium4 上工作的更新:

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
于 2021-05-19T12:04:00.970 回答
1

此代码片段适用于 Selenium 4.0:

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
于 2021-06-02T06:31:37.660 回答