Reputation: 19
Currently, in our framework, we have a function that does a SendKeys. Before of actually triggering the SendKeys we request for the value, and after the sendkeys we check if that value has changed, to trigger a javascript function to set the value of the field. This is in case the SendKeys method didn't work (we've had an specific case).
Thing is, it is all happening so fast that when it request for the field value after the SendKeys method, it hasn't changed, so it triggers the javascript function anyway.
Is there any way to avoid this, that doesn't involve putting a Thread.Sleep() in it?
Upvotes: 1
Views: 2118
Reputation: 7708
Alternatively, you can try Actions
class to send the text, Refer below java snippet:
public static void enterTextboxValue(WebDriver driver, WebElement element, String value) {
Actions navigator = new Actions(driver);
navigator.click(element).sendKeys(Keys.END).keyDown(Keys.SHIFT).sendKeys(Keys.HOME).keyUp(Keys.SHIFT)
.sendKeys(Keys.BACK_SPACE).sendKeys(value).perform();
if (element.getAttribute("value").contains(value)) {
System.out.println("Value [ " + value + " ] entered");
} else {
System.out.println("Unable to enter the value");
}
}
Upvotes: 1