如何在Selenium Java Client v3.11.0中删除超时和轮询时的弃用警告

时间:2018-04-06 07:35:00

标签: java selenium selenium-webdriver webdriver fluentwait

以下是我将Selenium Webdriver版本更新为3.11.0后显示为已弃用的代码。

    public getIntegrations(): Observable<EntityList<Integration>> {
    if (this.integrationsCache) {
      return Observable.of(this.integrationsCache);
    } else if (this.observable) {
      return this.observable;
    } else {
      this.observable = this.apiService.get('getIntegrations').map((result) => {
        this.observable = null;
        Log.create('getIntegrations.result').d(result);
        this.integrationsCache = result;

        return this.integrationsCache;
      }).share();

      return this.observable;
    }
  }

    public getScenarios(integrationId: string): Observable<EntityList<Scenario>> {

    return this.getIntegrations().map((result) => result[integrationId] ? result[integrationId].scenarios : {});
  }

在代码中的 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; } withTimeout部分显示已弃用的警告。

如何重写此代码,以便删除已弃用的警告。

由于我对硒新感到不确定这一变化。任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:12)

@Grasshopper的回答指出我们 FluentWait 的确切修改构造函数以及您从 withTimeout 和<删除弃用警告的要求strong> pollingEvery 字段。如果您遇到进一步的困难,可以使用下面的代码行:

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

您可以在The type FluentWait is not generic; it cannot be parameterized with arguments error for FluentWait Class through Selenium and Java

中找到详细的讨论

答案 1 :(得分:5)

检查FluentWait的源代码,提及使用Duration作为参数的方法。

  1. withTimeout - 使用withTimeout(Duration duration)方法。
  2. pollingEvery - 使用pollingEvery(Duration duration)方法。

答案 2 :(得分:4)

您可以使用以下代码行:

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