以下是我将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
部分显示已弃用的警告。
如何重写此代码,以便删除已弃用的警告。
由于我对硒新感到不确定这一变化。任何帮助将不胜感激。
答案 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);
中找到详细的讨论
答案 1 :(得分:5)
检查FluentWait的源代码,提及使用Duration作为参数的方法。
withTimeout(Duration duration)
方法。pollingEvery(Duration duration)
方法。答案 2 :(得分:4)
您可以使用以下代码行:
Wait<Browser> wait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(*timeToWaitInSec*))
.pollingEvery(Duration.ofMillis(*TimeToTryinMillisec*))
.ignoring(WebDriverException.class);