JSExecuter is use to run Javascript,
eg :
jsExecuter = (JavaScriptExecutor)driver;
jsExecuter.ExecuteScript(“any JavaScript”)
For JavaScript, text that we will use as java script, is fully a java script code . If we need a function output from that java script, we have to use ” return” before the script. For example, if we want title
jsExecuter.ExecuteScript(“return document.title”);
Sample JSexecuter ...
ExpectedCondition expectation = new ExpectedCondition() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) driver).executeScript(
"return document.readyState").equals("complete");
}
((JavascriptExecutor) driver)
.executeScript("function pageloadingtime()" + "{"
+ "return 'Page has completely loaded'" + "}
+ "return (window.onload=pageloadingtime());");
((JavascriptExecutor) driver)
.executeScript("window.AutomationTesting = true;");