2

I am using WebDriver with java. I want to input some text in a text field by using JavaScript. How can I do that?

1 Answer 1

2

Considering to input a text in Google search textfield, the following code should work:

WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('gbqfq').value = 'Ripon Al Wasim';");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.