In this chapter, we will look at how we can directly execute JavaScript snippets in Selenium. We will explore what you can do and how they can help you work around some of the limitations that you will come across while writing your scripts. We will also have a look at some examples of things that you should avoid doing.
The topics we will cover in this chapter will be:
- Using JavaScript to interact with the website loaded in your browser
- Injecting JavaScript libraries into the currently loaded website
- Performing complex actions using JavaScript
- Providing a way to allow user interaction with your tests by using JavaScript
To start off with, we are first going to have a look at how the JavascriptExecutor has been implemented in Selenium.