WebDriverWait is deprecated in Selenium 4 WebDriverWait is deprecated in Selenium 4 selenium selenium

WebDriverWait is deprecated in Selenium 4


It doesn't appear in the docs, but if you look at the source code you will see @Deprecated annotation

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

In the constructor description you have the solution

@deprecated Instead, use {@link WebDriverWait#WebDriverWait(WebDriver, Duration)}.

Which is the constructor being called from the deprecated one in any case.

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


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

Use this instead, only WebDriverWait(driver, clock) is supported;


This Warning message...

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

...implies that the current constructor of WebDriverWait have been deprecated.


Looking in to the code for WebDriverWait.java it seems:

  • The following methods are deprecated:

    • public WebDriverWait(WebDriver driver, long timeoutInSeconds)

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

      @Deprecatedpublic 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)

      @Deprecatedpublic WebDriverWait(    WebDriver driver, Clock clock, Sleeper sleeper, long timeoutInSeconds, long sleepInMillis) {  this(      driver,      Duration.ofSeconds(timeoutInSeconds),      Duration.ofMillis(sleepInMillis),      clock,      sleeper);}
  • Whilst the following methods were added:

    • 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;}

Hence you see the error.


However, I don't see any changes to WebDriverWait Class in Seleniumv4.0.0-alpha* Java client changelog and the functionality should continue to function as per the current implementation.

Selenium Java client v4.0.0-alpha-3 changelog:

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.

Conclusion

Selenium's Java client v4.0.0-alpha-3 is still a alpha release and needs to go through beta release and hence shouldn't be used for testing activity in production environment.


Solution

An immediate solution would be to downgrade to current released level Version 3.141.59