【发布时间】:2020-03-10 06:46:32
【问题描述】:
这是来自于等待的新 Selenium 文档的 sn-p:
WebDriver driver = new ChromeDriver();
driver.get("https://google.com/ncr");
driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER);
// Initialize and wait till element(link) became clickable - timeout in 10 seconds
WebElement firstResult = new WebDriverWait(driver, Duration.ofSeconds(10))
.until(ExpectedConditions.elementToBeClickable(By.xpath("//a/h3")));
当我粘贴这段代码时,它给了我一个关于持续时间的错误: 构造函数 WebDriverWait(WebDriver, Duration) 未定义
它仍然可以使用以下语法:
WebElement firstResult = new WebDriverWait(driver, 10)
.until(ExpectedConditions.elementToBeClickable(By.xpath("//a/h3")));
是文档错误吗?
【问题讨论】:
-
取决于文档的年龄。您没有提供文档链接,也没有告诉我们您使用的是哪个版本的 Selenium。
-
它可能是过时的代码 sn-p 或者您对它的解释不正确。
-
这里是最新官方文档的链接:selenium.dev/documentation/en/webdriver/waits。 Java客户端版本也是最新的——3.141.59。
-
@Vladimir 你可以在这里看到github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/…这个构造函数存在
-
@Vladimir 我没有回答你的问题。您可能想在 GitHub 上报告问题并在那里获得答案。另外,请查看我提供的构造函数
WebDriverWait(WebDriver driver, long timeoutInSeconds)的链接中已弃用。也许这些源代码尚未编译,将在 Selenium 4 中可用?
标签: java selenium selenium-webdriver