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 ...

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.