gpt4 book ai didi

java - 检查字符串时,until() 中出现 “FluentWait cannot be applied” 错误

转载 作者:行者123 更新时间:2023-12-01 19:57:57 24 4
gpt4 key购买 nike

我有一个 Selenium 测试,用于检查测试页上是否可以看到某个字符串。我的想法是,如果页面没有立即加载,则使用显式等待。

WebElement element = driver.findElement(By.xpath("//*[text()='text']"));

之后我做了:

    WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(element));

因此在继续之前最多有 10 秒的等待时间。如果它在 10 秒内看到该元素,则测试将继续。

但是我在 wait.until 时收到以下错误

until
(java.util.function.Function<? super org.openqa.selenium.WebDriver,java.lang.Object>)
in FluentWait cannot be applied
to
(org.openqa.selenium.support.ui.ExpectedCondition<org.openqa.selenium.WebElement>)
 

使用谷歌来解决这个问题并没有帮助我。有人知道如何解决这个错误吗?

该元素包含我想要的字符串

最佳答案

正如您在问题中提到的“检查测试页面上是否可以看到某个字符串”作为“验证点”来说太宽泛了。理想情况下,您应该验证 WebElement 中是否存在预期文本。为此,您必须使用 Locator Strategy 之一先识别元素再归纳WebDriverWait具有适当的ExpectedConditions验证文本如下:

步骤

  • 找到 WebElement:

    WebElement element = driver.findElement(Locator Strategy);
  • textToBePresentInElement 引发WebDriverWait :

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.textToBePresentInElement(element, "text_to_be_validated"));

关于java - 检查字符串时,until() 中出现 “FluentWait cannot be applied” 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48828827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com