13
Dec

Execute javascript via Selenium WebDriver

System.setProperty("webdriver.chrome.driver", "./chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.co.in");
String javaScript = "document.getElementsByName(\"q\")[0].value='txt val'";
((JavascriptExecutor)driver).executeScript(javaScript);
Thread.sleep(20000);
driver.quit();