Try triggering the onchange
or associated event using the below funciton.
public static void jsTriggerEventOnElement(WebDriver driver, WebElement element, String eventName) {
String jsFunction = " var genericEvent = document.createEvent ('Event'); clickEvent.initEvent ('" + eventName + "', true, true); arguments [0].dispatchEvent (genericEvent); ";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(jsFunction, element);
}
You can trigger the event by using the below line of code after entering the value in the field.
// enter the value using the normal send_keys/js
// now call the jsTriggerEventOnElement method, here we are triggering the onchange event
// please change the event based the associated event
jsTriggerEventOnElement(driver, element, 'onchange`)
Please refer to this post that will give an idea to find out the associated events. But, you can always try with onchange
as a first check.
Edit
Try with the below.
public static void jsTriggerEventOnElement(WebDriver driver, WebElement element, String eventName) {
String jsFunction = " var clickEvent = document.createEvent ('Event'); clickEvent.initEvent ('" + eventName + "', true, true); arguments [0].dispatchEvent (clickEvent); ";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(jsFunction, element);
}
jsTriggerEventOnElement(driver,element, 'onblur');