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
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;
}
});
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
A one liner that works and uses lambda function.
wait.until((ExpectedCondition<Boolean>) driver -> driver.findElement(By.id("elementId")).getAttribute("value").length() != 0);
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With