The JavascriptExecutor class
The Selenium JavascriptExecutor
class allows users to inject JavaScript commands directly into the context of the active browser frame or window. The use of this method is required in cases where the standard WebDriver
class's methods fail to find or act upon an element on the browser page. JavaScript commands can be executed synchronously or asynchronously on the page. The class is an interface, and has been implemented for all the current driver classes. When designing a class to utilize this interface, users can pass commands directly to a WebElement by using the static locator, or one of the common locator methods available to WebDriver
. Some of the more common methods will be outlined here:
Note
The JavaDoc for the JavascriptExecutor
class is located at https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html.
/** * Selenium JavaScript Executor Utility Class * */ public class JavaScriptUtils { // constructor ...