How to remove deprecation warning on timeout and polling in Selenium Java Client v3.11.0
Asked Answered
E

4

10

Below is my code which is showing as deprecated after I have been updated the Selenium Webdriver version to 3.11.0.

    private Wait<WebDriver> mFluentWait(WebDriver pDriver) {
    Wait<WebDriver> gWait = new FluentWait<WebDriver>(pDriver).withTimeout(100, TimeUnit.SECONDS)
            .pollingEvery(600, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class);   
    return gWait;
}

Showing deprecated warning in withTimeout and pollingEvery section in the code.

How can I rewrite this code so that I can remove the deprecated warning.

Since am new to selenium am not sure about the change. Any help will be appreciated.

Erasmoerasmus answered 6/4, 2018 at 7:34 Comment(2)
Possible duplicate of Selenium Webdriver 3.0.1-[Eclipse-Java-Chrome]: Selenium showing error for FluentWait ClassSeptime
@DebanjanB I am not getting any errors on executing, the withTimeout and pollingEvery section in the code is showing as deprecated. When I referred the selenium documents , it is showing in the deprecated lists. So I want to remove the deprecated parts in the code and want to rewrite the method. I think you have understood the difference between the question you mentioned and I have asked.Erasmoerasmus
S
16

@Grasshopper 's answer points us to the exact modified constructor of FluentWait and your requirement of removing the deprecation warning from withTimeout and pollingEvery fields. Incase you are facing further difficulty you can use the line of code below :

import java.time.Duration;
//lines of code
Wait<WebDriver> gWait = new FluentWait<WebDriver>(pDriver).withTimeout(Duration.ofSeconds(100))
        .pollingEvery(Duration.ofMillis(600)).ignoring(NoSuchElementException.class);

You can find a detailed discussion in The type FluentWait is not generic; it cannot be parameterized with arguments error for FluentWait Class through Selenium and Java

Septime answered 6/4, 2018 at 10:18 Comment(1)
This is what am exactly looking for. Thank you so much.Erasmoerasmus
A
8

Check the source code of FluentWait which mentions to use the methods using Duration as arguments instead.

  1. withTimeout - Use the withTimeout(Duration duration) method.
  2. pollingEvery - Use the pollingEvery(Duration duration) method.
Among answered 6/4, 2018 at 8:51 Comment(0)
I
6

you can use following lines of code:

  Wait<Browser> wait = new FluentWait<>(driver)
            .withTimeout(Duration.ofSeconds(*timeToWaitInSec*))
            .pollingEvery(Duration.ofMillis(*TimeToTryinMillisec*))
            .ignoring(WebDriverException.class);
Irritating answered 16/7, 2018 at 17:40 Comment(0)
H
0

After the upgrade to Selenium 4, few of the old methods have been deprecated of which Fluent wait is part of.

Use the below code in the similar order for seamless execution:

 Wait<Browser> wait = new FluentWait<>(driver)
            .withTimeout(Duration.ofSeconds(*timeToWaitInSec*))
            .ignoring(WebDriverException.class)
            .pollingEvery(Duration.ofMillis(*TimeToTryinMillisec*));

Also refer for below article for the other changes/upgrade in Selenium 4.

https://applitools.com/blog/selenium-4-migration/

Handgun answered 25/2, 2022 at 6:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.