【问题标题】:How to wait until text box is empty selenium java?如何等到文本框为空 selenium java?
【发布时间】:2022-01-28 14:27:00
【问题描述】:

我的场景是

  1. 在文本框中输入值。
  2. 点击清除按钮。
  3. 等到文本框清除。

【问题讨论】:

  • 我可以使用线程。睡觉,但我不想用它。
  • 尝试使用带有显式等待的textMatches。匹配空/空字符串
  • 使用 wait.until(ExpectedConditions.textToBePresentInElement(webelement, ""));但问题还是一样。
  • 按照建议尝试使用 textMatches
  • org.openqa.selenium.support.ui.ExpectedConditions 中的任何一个在调用时都必须为 false,否则会抛出 org.openqa.selenium.TimeoutException。

标签: java selenium selenium-webdriver


【解决方案1】:

试试这个:

public static Boolean textMatchTest(WebDriver driver, By locator, String expectedText) {
    Boolean textMatch = null;
    WebElement element = driver.findElement(locator);
    if (element.getText().equals(expectedText)) {
        textMatch = true;
    }
    else {
        try {
            new WebDriverWait(driver, 10).until(textToBe(locator, expectedText));
            textMatch = true;
        }
        catch (TimeoutException timeoutException) {
            textMatch = false;
        }
    }
    return textMatch;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-12
    • 2013-05-05
    • 1970-01-01
    • 2019-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多