@Rohan, JavaScript executor is an interface of Selenium WebDriver that has the functionality similar to that of Java Script and can interact with HTML DOM elements. Instead of using driver.findElement method of the Selenium WebDriver we can use JavaScriptExecutor Interface to perform similar action on the Page. It provides advantages over FindElement method while handling tricky XPath as well as finding element which are sometimes hidden.
Not only that, we can perform several other Java Script actions such as Browser Object Model (BOM), AJAX in addition to HTML DOM actions with the help of JavaScript Executor. Some scenarios we could handle using JavaScript Executor are:
-
To type Text in Selenium WebDriver without using sendKeys() method
-
To click a Button in Selenium WebDriver using JavaScript
-
To handle Checkbox
-
To generate Alert Pop window in selenium
-
To refresh browser window using Javascript
-
To get innertext of the entire webpage in Selenium
-
To get the Title of our webpage
-
To get the domain
-
To get the URL of a webpage
-
To perform Scroll on an application using Selenium
-
To click on a SubMenu which is only visible on mouse hover on Menu
-
To navigate to different page using Javascript