selenium Selify 4中不推荐使用WebDriverWait

c6ubokkw  于 2022-11-10  发布在  其他
关注(0)|答案(6)|浏览(295)

我得到了一个
警告:(143,13)‘WebDriverWait(org.Openqa.selenium.WebDriver,Long)’已弃用
在 selenium 4.0.0-α-3中。
但官方的Selenium page只列出了

WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds, long sleepTimeOut)

已被弃用。
怎么啦?我在用IntelliJ,会不会是他们的问题?

91zkwejq

91zkwejq1#

它没有出现在文档中,但如果您查看source code,您将看到@Deprecated注解

@Deprecated
public WebDriverWait(WebDriver driver, long timeoutInSeconds) {
    this(driver, Duration.ofSeconds(timeoutInSeconds));
}

在构造函数描述中,您有解决方案
@已弃用,请使用{@link WebDriverWait#WebDriverWait(WebDriver,Duration)}。
在任何情况下都是从已弃用的构造函数调用的构造函数。

new WebDriverWait(driver, Duration.ofSeconds(10));
643ylb08

643ylb082#

像您所说的那样,使用Selume4编写它,因为您尝试使用的内容已被弃用。
第一次进口。

import java.time.Duration;

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(30));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(60));

为了流畅的等待。

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
        .withTimeout(Duration.ofSeconds(30))
        .pollingEvery(Duration.ofSeconds(5))
        .ignoring(NoSuchElementException.class);

WebDriverWait语句

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));
7ivaypg9

7ivaypg93#

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

改用这个吧。目前仅支持WebDriverWait(驱动程序、时钟);

92dk7w1h

92dk7w1h4#

提供以下警告的代码:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

警告:
WebDriver.Timeouts类型的方法implicitlyWait(long, TimeUnit)已弃用。
在Selify 4上运行的更新:

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
z9ju0rcb

z9ju0rcb5#

此警告消息..。

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

因此,您可以看到错误。
但是,我在**Selifyv4.0.0-AlphaJava客户端更改日志中没有看到WebDriverWait类有任何变化,该功能应该会继续按照当前的实现运行。

Selify Java客户端v4.0.0-alpha-3 ChangeLog:

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.

结论

  • Selify的Java客户端V4.0.0-Alpha-3仍是Alpha版本,需要通过beta*版本,不能用于生产环境中的测试活动。

解决方案

一个直接的解决方案是降级到当前发布的级别Version 3.141.59

dphi5xsq

dphi5xsq6#

下面的代码片段适用于Selenium4.0:

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

相关问题