From the course: Selenium Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Executing JavaScript commands

Executing JavaScript commands - Selenium Tutorial

From the course: Selenium Essential Training

Start my 1-month free trial

Executing JavaScript commands

- [Instructor] JavaScript commands can sometimes be necessary in WebDriver tests. Luckily, Selenium supports the JavascriptExecutor. The JavascriptExecutor provides two methods to run JavaScript on the selected window or current page. First is the executeAsyncScript method. This executes an asynchronous piece of JavaScript, and scripts executed with this method must explicitly signal they are finished by invoking the provided callback. There is also the executeScript method. In this method executes JavaScript as the body of an anonymous function. There are a few use cases for using the JavascriptExecutor. First, I've used it when Selenium WebDriver fails to click on any element due to some issue. It can also generate alerts and run other scripts to trigger actions on a page. And third, it can manipulate the page and perform actions like scrolling and zooming. So, in this video, I'll demonstrate a simple example of using the JavascriptExecutor to click on an element within a modal that…

Contents