此警告消息...
Warning: (143,13) 'WebDriverWait(org.openqa.selenium.WebDriver, long)' is deprecated
...意味着WebDriverWait的当前构造函数已被弃用。
查看WebDriverWait.java的代码似乎:
不推荐使用以下方法:
public WebDriverWait(WebDriver driver, long timeoutInSeconds)
@Deprecated
public WebDriverWait(WebDriver driver, long timeoutInSeconds) {
this(driver, Duration.ofSeconds(timeoutInSeconds));
}
public WebDriverWait(WebDriver driver, long timeoutInSeconds, long sleepInMillis)
@Deprecated
public WebDriverWait(WebDriver driver, long timeoutInSeconds, long sleepInMillis) {
this(driver, Duration.ofSeconds(timeoutInSeconds), Duration.ofMillis(sleepInMillis));
}
public WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeoutInSeconds, long sleepInMillis)
@Deprecated
public WebDriverWait(
WebDriver driver, Clock clock, Sleeper sleeper, long timeoutInSeconds, long sleepInMillis) {
this(
driver,
Duration.ofSeconds(timeoutInSeconds),
Duration.ofMillis(sleepInMillis),
clock,
sleeper);
}
虽然添加了以下方法:
public WebDriverWait(WebDriver driver, Duration timeout)
/**
* @param driver The WebDriver instance to pass to the expected conditions
* @param timeout The timeout when an expectation is called
* @see WebDriverWait#ignoring(java.lang.Class)
*/
public WebDriverWait(WebDriver driver, Duration timeout) {
this(
driver,
timeout,
Duration.ofMillis(DEFAULT_SLEEP_TIMEOUT),
Clock.systemDefaultZone(),
Sleeper.SYSTEM_SLEEPER);
}
public WebDriverWait(WebDriver driver, Duration timeout, Duration sleep)
/**
* 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 timeout The timeout in seconds when an expectation is called
* @param sleep The duration in milliseconds to sleep between polls.
* @see WebDriverWait#ignoring(java.lang.Class)
*/
public WebDriverWait(WebDriver driver, Duration timeout, Duration sleep) {
this(driver, timeout, sleep, Clock.systemDefaultZone(), Sleeper.SYSTEM_SLEEPER);
}
WebDriver driver, Duration timeout, Duration sleep, Clock clock, Sleeper sleeper)
/**
* @param driver the WebDriver instance to pass to the expected conditions
* @param clock used when measuring the timeout
* @param sleeper used to make the current thread go to sleep
* @param timeout the timeout when an expectation is called
* @param sleep the timeout used whilst sleeping
*/
public WebDriverWait(WebDriver driver, Duration timeout, Duration sleep, Clock clock, Sleeper sleeper) {
super(driver, clock, sleeper);
withTimeout(timeout);
pollingEvery(sleep);
ignoring(NotFoundException.class);
this.driver = driver;
}
因此,您会看到错误。
但是,我没有看到Selenium v4.0.0-alpha*WebDriverWait
Java 客户端更改日志中的Class 有任何更改,并且该功能应继续按照当前实现运行。
Selenium Java 客户端v4.0.0-alpha-3
更新日志:
v4.0.0-alpha-3
==============
* Add "relative" locators. The entry point is through the `RelativeLocator`.
Usage is like `driver.findElements(withTagName("p").above(lowest));`
* Add chromedriver cast APIs to remote server (#7282)
* `By` is now serializable over JSON.
* Add ApplicationCache, Fetch, Network, Performance, Profiler,
ResourceTiming, Security and Target CDP domains.
* Fixing Safari initialization code to be able to use Safari Technology
Preview.
* Ensure that the protocol converter handles the new session responses
properly.
* Expose devtools APIs from chromium derived drivers.
* Expose presence of devtools support on a role-based interface
* Move to new Grid, deleting the old standalone server and grid implementation.
* Switch to using `HttpHandler` where possible. This will impact projects that
are extending Selenium Grid.
* Respect "webdriver.firefox.logfile" system property in legacy Firefox driver.
Fixes #6649
* Back out OpenCensus support: OpenTracing and OpenCensus are merging, so
settle on one for now.
* Only allow CORS when using a —allow-cors flag in the Grid server
* If you're using the Java Platform Module System, all modules
associated with the project are generated as "open" modules. This
will change in a future release.
* The version of Jetty being used is unshadowed.
结论
Selenium 的 Java 客户端 v4.0.0-alpha-3仍然是一个alpha版本,需要通过beta版本,因此不应该用于生产环境中的测试活动。
解决方案
一个直接的解决方案是降级到当前发布的级别 版本 3.141.59