How do I use sendKeys in JavaScriptExecutor?
Even though sendKeys() most often works, there may be times when the text input box is disabled, and you need to pass text to the field. In such cases, sendKeys() would fail, and you would have to try another method like JavaScript Executer.
JavascriptExecutor jse = ((JavascriptExecutor)driver); WebElement email = driver.findElement(By.id(“useremail”)); jse.executeScript(“arguments[0].value=‘—your email id—’;”, email);
However, this is not the recommended testing method because the UI prevents you from entering any text into a field.
For more info, refer to our blog on Selenium SendKeys.