WebDriverWait is not recognized even though it is imported in the eclipse IDE.
Does anyone know the possible reason and fix for this?
Advertisement
Answer
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.