O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling a simple JavaScript alert

Web developers use JavaScript alerts for informing users about validation errors, warnings, getting a response for an action, accepting an input value, and so on.

Tests will need to verify that the user is shown correct alerts while testing. It would also be required to handle alerts while performing an end-to-end workflow. The Selenium WebDriver provides an Alert class for working with JavaScript alerts.

In this recipe, we will handle a simple alert box using Selenium WebDriver's Alert class. A simple alert box is often used to notify the user with information such as errors, warnings, and success. When an alert box pops up, the user will have to click on the OK button to proceed, as shown in the following screenshot: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required