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

标签 java selenium selenium-webdriver webdriverwait

我有一个 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/

相关文章:

java - 是否可以仅针对特定风格包含并初始化 HockeyApp SDK?

java - COMPUTE_MAXS 正在删除 StackMapTable

java - Selenium 链接 CSS 选择器

RS Selenium : Can't see Browser as I run my Code

selenium - 使用 SendKeys 向 IE 11 发送 '@' 特殊字符

java - BufferedWriter 写入时清除文本文件

java - 我如何在java中递归地重新排列字符串

javascript - Selenium 服务器已启动并正在运行,但无法连接到 selenium

python - 无效元素状态异常 : Message: invalid element state: Element is not currently interactable and may not be manipulated

Python Splinter (SeleniumHQ) 如何截取多个网页? [连接被拒绝]