Handling a confirm and prompt alert box
A confirm box is often used to verify or accept something from the user. When a confirm alert is displayed, the user will have to click on either the OK or the Cancel button to proceed, as shown in the following screenshot:
If the user clicks on the OK button, the confirm box returns a true
value response. If the user clicks on the Cancel button, then it returns false
.
The prompt alert box
A prompt box is often used to accept a value from a user. When a prompt box pops up, the user will have to enter a value and click on either the OK or the Cancel button to proceed, as shown in the following screenshot:
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 confirm and prompt boxes using the Selenium WebDriver's Alert
interface.
How to do it...
Let's create a set of tests that can handle a confirm box displayed on a page, as follows:
In the
testConfirmAccept...