'The constructor WebDriverWait(chromeDriver, int) is undefined [closed]

WebDriverWait is not recognized even though it is imported in the eclipse IDE.

enter image description here

Does anyone know the possible reason and fix for this?



Solution 1:[1]

You are trying to use

new WebDriverWait(driver, 10);

which will call this constructor

  /**
   * 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 timeoutInSeconds The timeout in seconds when an expectation is called
   * @see WebDriverWait#ignoring(java.lang.Class)
   * @deprecated Instead, use {@link WebDriverWait#WebDriverWait(WebDriver, Duration)}.
   */
  @Deprecated
  public WebDriverWait(WebDriver driver, long timeoutInSeconds) {
    this(driver, Duration.ofSeconds(timeoutInSeconds));
  }

As you can see, it has been deprecated in newer version of Selenium i.e Selenium 4

Solution:

You should rather use this constructor:

  public WebDriverWait(WebDriver driver, Duration timeout) {
    this(
        driver,
        timeout,
        Duration.ofMillis(DEFAULT_SLEEP_TIMEOUT),
        Clock.systemDefaultZone(),
        Sleeper.SYSTEM_SLEEPER);
  }

Your effective code:

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

should get the job done for you.

Solution 2:[2]

WebDriverWait is missing from your project. 1.Check you have used the import the statement org.openqa.selenium.support.ui 2. Either add the jar manually to the project (or) if it is Maven based project use mvn clean install , and reopen the IDE- you should be good.

Solution 3:[3]

WebDriverWait w=new WebDriverWait(driver,10) 

basically, this is deprecated.

This issue can be suppressed by changing the above statement in the following ways

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

WebDriverWait webdwait = new WebDriverWait(driver, Duration.ofHours(10));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cruisepandey
Solution 2 mk7644
Solution 3 Suraj Rao