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 confirm box alert

A confirm box is often used to verify or accept something from the user. When a confirm box pops up, the user will have to click either on the OK or the Cancel button to proceed, as shown in the following screenshot:

Handling a confirm box alert

If the user clicks on the OK button, the box returns true. If the user clicks on the Cancel button, the box returns false.

In this recipe, we will handle a confirm box using the Selenium WebDriver's Alert class.

How to do it...

Let's create a set of tests that handle a confirm box displayed on a page as follows:

  1. In the testConfirmAccept test, we will accept the confirm box and verify a message on the page when ...

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