【问题标题】:Is it a bug in Selenium documentation?它是 Selenium 文档中的错误吗?
【发布时间】: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


【解决方案1】:

正如我在原始问题中所写,

WebElement firstResult = new WebDriverWait(driver, 10)
                .until(ExpectedConditions.elementToBeClickable(By.xpath("//a/h3")));

上面的代码仍然有效。我想,正如@Fenio 所假设的那样,新语法将在 Selenium 4 中可用,因为它存在于 GitHub 中。

【讨论】:

    【解决方案2】:

    你可以试试这个,

    他没有错。

    WebDriverWait wdw = new WebDriverWait(driver, 10);
    wdw.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a/h3")));
    

    【讨论】:

      【解决方案3】:

      试试这个,肯定可以的:

      WebDriverWait w=new WebDriverWait(driver, Duration.ofSeconds(5));
      

      WebDriverWait 类型中的TimeUnit 已弃用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-23
        • 2018-12-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多