Wait Till Text Present In Text Field

前端 未结 6 962
死守一世寂寞
死守一世寂寞 2020-12-05 15:27

In webdriver, how to ask to webdriver to wait until text is present in text field.

actually i have one kendo text field whose values comes from database which takes

相关标签:
6条回答
  • 2020-12-05 15:57

    A one liner that works and use lambda function.

    wait.until((ExpectedCondition<Boolean>) driver -> driver.findElement(By.id("elementId")).getAttribute("value").length() != 0);
    
    0 讨论(0)
  • 2020-12-05 15:59

    Using WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait) and ExpectedCondition (org.openqa.selenium.support.ui.ExpectedConditions) objects

    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("element_id"), "The Text"));
    
    0 讨论(0)
  • 2020-12-05 16:02

    This is my solution for sending text to input:

      public void sendKeysToElement(WebDriver driver, WebElement webElement, String text) {
        WebDriverWait wait = new WebDriverWait(driver, Configuration.standardWaitTime);
        try {
    
            wait.until(ExpectedConditions.and(
                    ExpectedConditions.not(ExpectedConditions.attributeToBeNotEmpty(webElement, "value")),
                    ExpectedConditions.elementToBeClickable(webElement)));
    
            webElement.sendKeys(text);
    
            wait.until(ExpectedConditions.textToBePresentInElementValue(webElement, text));
    
            activeElementFocusChange(driver);
    
        } catch (Exception e) {
            Configuration.printStackTraceException(e);
        }
    }
    
    WebElement nameInput = driver.findElement(By.id("name"));
    sendKeysToElement(driver, nameInput, "some text");
    
    0 讨论(0)
  • 2020-12-05 16:03

    You can use WebDriverWait. From docs example:

     (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver d) {
                    return d.findElement(...).getText().length() != 0;
                }
            });
    
    0 讨论(0)
  • 2020-12-05 16:14

    You can use a simple method in which you need to pass driver object webelement in which text is going to come and the text which is goint to come.

    public static void waitForTextToAppear(WebDriver newDriver, String textToAppear, WebElement element) {
        WebDriverWait wait = new WebDriverWait(newDriver,30);
        wait.until(ExpectedConditions.textToBePresentInElement(element, textToAppear));
    }
    
    0 讨论(0)
  • 2020-12-05 16:22

    You can use WebDriverWait. From docs example:
    above ans using .getTex() this is not returning text from input field

    use .getAttribute("value") instead of getText()

    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.findElement(...).getAttribute("value").length() != 0;
        }
    });
    

    tested 100% working hope this will help

    0 讨论(0)
提交回复
热议问题