Handling a prompt box alert

A prompt box is often used to input a value by the user before entering a page. When a prompt box pops up, the user will have to click either on the OK or the Cancel button to proceed after entering an input value, as shown in the following screenshot:

Handling a prompt box alert

If the user clicks on the OK button, the box returns the input value. If the user clicks on the Cancel button, the box returns null.

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

How to do it...

We will create a test that handles a prompt box. We will enter text into the prompt box's input field and later verify if the same value is ...

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.