Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebDriverWait is deprecated in Selenium 4

I'm getting a

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

in Selenium 4.0.0-alpha-3.

But official Selenium page lists only

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

as deprecated.

What is wrong? I'm using IntelliJ, could it be their issue?

like image 795
Mate Mrše Avatar asked Nov 22 '19 11:11

Mate Mrše


4 Answers

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

@Deprecated
public 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));
like image 60
Guy Avatar answered Sep 16 '22 13:09

Guy


Write it like this with Selenium 4 since what you tried to use is deprecated, as you said. First import.

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));

For fluent wait.

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

WebDriverWait statement

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));
like image 21
Sameera De Silva Avatar answered Sep 18 '22 13:09

Sameera De Silva


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

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

like image 43
PDHide Avatar answered Sep 17 '22 13:09

PDHide


Code which gives the below warning:

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

Warning:
The method implicitlyWait(long, TimeUnit) from the type WebDriver.Timeouts is deprecated.

Update which works on selenium4:

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
like image 29
Geetu Dhillon Avatar answered Sep 18 '22 13:09

Geetu Dhillon