Mat*_*rše 3 java selenium selenium-webdriver webdriverwait selenium4
我得到一个
警告:(143,13) 'WebDriverWait(org.openqa.selenium.WebDriver, long)' 已弃用
在硒 4.0.0-alpha-3 中。
但官方Selenium 页面仅列出
WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds, long sleepTimeOut)
Run Code Online (Sandbox Code Playgroud)
已弃用。
怎么了?我正在使用 IntelliJ,这可能是他们的问题吗?
Sam*_*lva 19
用 Selenium 4 这样写,因为正如您所说,您尝试使用的内容已被弃用。
首先导入。
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));
Run Code Online (Sandbox Code Playgroud)
为了流畅的等待。
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);
Run Code Online (Sandbox Code Playgroud)
WebDriverWait 语句
WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));
Run Code Online (Sandbox Code Playgroud)
它没有出现在文档中,但是如果您查看源代码,您将看到@Deprecated
注释
@Deprecated
public WebDriverWait(WebDriver driver, long timeoutInSeconds) {
this(driver, Duration.ofSeconds(timeoutInSeconds));
}
Run Code Online (Sandbox Code Playgroud)
在构造函数描述中,您有解决方案
@deprecated 相反,使用 {@link WebDriverWait#WebDriverWait(WebDriver, Duration)}。
在任何情况下,哪个是从已弃用的构造函数中调用的构造函数。
new WebDriverWait(driver, Duration.ofSeconds(10));
Run Code Online (Sandbox Code Playgroud)
小智 9
给出以下警告的代码:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)
警告:
implicitlyWait(long, TimeUnit)
该类型的方法WebDriver.Timeouts
已被弃用。
适用于 Selenium 4 的更新:
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
Run Code Online (Sandbox Code Playgroud)
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Run Code Online (Sandbox Code Playgroud)
用这个代替。仅支持WebDriverWait(driver,clock);
归档时间: |
|
查看次数: |
12814 次 |
最近记录: |