JavaScript Alerts - Instructions

All the dialogs and alerts are triggered by JavaScript and use default browser functionality. This page demonstrates three types of JavaScript alert box. It is important to know how to automate these and distinguish them from dialog box functionality implemented via CSS.

Alert Box

The Alert Box is used for information, it contains a message and a single [OK] button to dismiss the alert.

Confirm Box

The Confirm Box allows more complex interaction.

In addition to [OK], there is a [Cancel] button.

Prompt Box

The Prompt Box additionally allows the input of text. This text is only returned to the application if the user clicks [OK].

DOM Interaction

For each of alert types, the action taken by the user will be displayed on the page.

Additionally an attribute on the trigger buttons will count the number of times the dialog has been displayed.

Automating Alert, Confirm, Prompt Box

JavaScript provides three types of alerts: Alert, Confirm, Prompt.

Because these are implemented by browsers themselves, most automated execution tools have specific methods for dealing with them.

e.g. when using WebDriver we switch to the alert driver.switchTo().alert() and then dismiss() or accept() etc.