JavaScript Executor functions for Selenium
In this article we will learn about different action types we can perform using JavaScript Executor. Sometime we are not able to accomplish the task using traditional methods of Selenium, to handle those cases Javascript can come in handy with the solutions. JavaScript Executor functions for Selenium JavaScriptExecutor is an interface that helps to execute JavaScript through Selenium WebDriver. It provides executeScript and executeAsyncScript methods to run Javascript on selected frames or windows. If you are appearing for the written test in Nagarro, you might find a lot of questions on the syntax of Javascript Executor in your paper. Click Operation using JavaScript Executor JavaScriptExecutor js = (JavaScriptExecutor)driver; js.executeScript(" arguments[0].click();", button); Explanation - We have to typecast driver each time we use javascript executor. Scroll into a particular element using JavaScript Executor js.executeScript("arguments[0].scrollIntoView()", ...