What is JavaScriptExecutor in Selenium?

What is JavaScriptExecutor?JavaScriptExecutor is an interface which provides mechanism to execute Javascript through selenium driver. It provides “executescript” & “executeAsyncScript” methods, to run JavaScript in the context of the currently selected frame or window.

Lets inject Javascript into Browser using Selenium

Why we use it?To enhance the capabilities of the existing scripts by performing javascript injection into our application under test.In simple words “Javascript can be executed within the browser with the help of JavaScript Executor.”Package:-import org.openqa.selenium.JavascriptExecutor;Syntax:-