Wait until the text appears in the text box

In webdriver, how to ask webdriver to wait until the text appears in the text box.

In fact, I have one kendo text field whose values ​​come from a database, which takes some time to load. After downloading, I can continue.

Please help us with this.

+6
source share
6 answers

You can use WebDriverWait. From the sample documentation:

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

You can use a simple method in which you need to pass the web element of the driver object into which the text will go and the text that should match.

 public static void waitForTextToAppear(WebDriver newDriver, String textToAppear, WebElement element) { WebDriverWait wait = new WebDriverWait(newDriver,30); wait.until(ExpectedConditions.textToBePresentInElement(element, textToAppear)); } 
+2
source

You can use WebDriverWait. From the sample documents:
above ans using .getTex (), this does not return text from the 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 helps

+2
source

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

 WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.textToBePresentInElement(By.id("element_id"), "The Text")); 
0
source

This is my solution to send text for 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
source

One liner that works and uses the lambda function.

 wait.until((ExpectedCondition<Boolean>) driver -> driver.findElement(By.id("elementId")).getAttribute("value").length() != 0); 
0
source

All Articles