Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait Till Text Present In Text Field

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 some time to load. Once it load i can proceed further.

please help on this

like image 259
Lavish Karankar Avatar asked Mar 27 '13 10:03

Lavish Karankar


4 Answers

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;
            }
        });
like image 125
Dakshinamurthy Karra Avatar answered Sep 23 '22 20:09

Dakshinamurthy Karra


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

like image 30
code.rider Avatar answered Sep 21 '22 20:09

code.rider


A one liner that works and uses lambda function.

wait.until((ExpectedCondition<Boolean>) driver -> driver.findElement(By.id("elementId")).getAttribute("value").length() != 0);
like image 37
Gico Avatar answered Sep 21 '22 20:09

Gico


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"));
like image 39
SilverColt Avatar answered Sep 20 '22 20:09

SilverColt