Executing JavaScript code

Selenium WebDriver API provides the ability to execute JavaScript code with the browser window. This is a very useful feature where tests need to interact with the page using JavaScript. Using this API, client-side JavaScript code can also be tested using Selenium WebDriver. Selenium WebDriver provides a JavascriptExecutor interface that can be used to execute arbitrary JavaScript code within the context of the browser.

In this recipe, we will explore how to use JavascriptExecutor for executing JavaScript code. This book has various other recipes where JavascriptExecutor has been used to perform some advanced operations that are not yet supported by the Selenium WebDriver.

How to do it...

Let's create a test that will call ...

Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.