I'm currently developing an automation flow using IE 11 with Selenium and Java. On a particular web page, I need to input a value in a Text Box and then press Enter. I have successfully managed to input the values using the following code:
// The 'box' variable is a webElement
JavascriptExecutor js = (JavascriptExecutor)iedriver;
js.executeScript("arguments[0].value='1500';", box);
Although this code works as expected for entering the value, I encountered an issue when trying to use box.sendKeys(Keys.Enter)
. This method did not work as intended. So, I am exploring alternative ways to achieve "pressing the Enter key via JavaScript".
I also attempted the following code snippet, but it too did not produce the desired outcome:
Actions actions = new Actions(iedriver);
actions.moveToElement(box).sendKeys(Keys.RETURN).build().perform();
While no error messages are generated and the code executes without issues, the Enter Key is not effectively pressed on the web page.