JavaScriptExecutor in Selenium

Price: INR 8,999.00
Price: INR 14,999.00
Was: INR 16,999.00

Let’s see the JavaScriptExecutor in Selenium. JavaScriptExecutor is an interface which provides the mechanism to execute Javascript through selenium driver.

It provides “execute script” & “executeAsyncScript” methods, to run JavaScript in the context of the currently selected frame or window.


JavaScriptExecutor enhances the browser performance. We use the JavaScriptExecutor to execute the within the browser.

Syntax –

JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript(Script,Arguments);


Here the Script – is JavaScript to Execute and Arguments – The arguments to the script.

Let’s some scenarios using JavaScriptExecutor.

1. Generate Alert using JavScriptExecutor


2. Click Button using JavScriptExecutor –


3. Refresh browser window using Javascript –


4. Get inner text of the entire webpage in Selenium –


5. Get the Title of our webpage in Selenium –


6. Perform Scroll on application using  Selenium –


7. Navigate to different page using Javascript –


So this is the way, How we can use the JavaScript executor with Selenium.

We have seen the all important scenarios with java script executor.

0 Comment

Leave a Reply