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

我是研究僧i 提交于 2020-04-06 02:39:28

问题


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.


回答1:


@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




回答2:


you can use following lines of code:

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



回答3:


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.


来源:https://stackoverflow.com/questions/49687699/how-to-remove-deprecation-warning-on-timeout-and-polling-in-selenium-java-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!