O'Reilly logo

Selenium Essentials by Prashanth Sams

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The JavascriptExecutor class

JavascriptExecutor is a class under the Selenium library that executes JavaScript code snippets. For example, a Selenium WebDriver command such as WebElement.click() might not work on all browsers, but JavaScriptExecutor could help you to click on an element in any browser by executing the appropriate JavaScript snippet. There are a couple of Selenium WebDriver functions to handle JavaScript, such as executeAsyncScript() and executeScript(). The executeAsyncScript() method lets you inject JavaScript snippets into the page for asynchronous execution. The following is the syntax for this method:

JavascriptExecutor jse = (JavascriptExecutor)driver;

Let's see how you can click on an element without using Selenium's click() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required