Skip to content
CodeKruPro

Handle a confirm box: OK or Cancel

Automation taskEasy-MediumAsked in: Capgemini, Infosys, TCS, Wipro

"How do you click Cancel on a confirm box?" Accept clicks OK and dismiss clicks Cancel. After either one, read the result the page shows, because the page reacts differently to each choice.

Handle Confirm Alert

Handle Confirm Alert

A confirm alert has two buttons: OK and Cancel. Use accept() for OK and dismiss() for Cancel.

On the Alerts page, clicking "Show Confirm" shows a confirm dialog. The result appears in id="confirmResult".

Task:

  1. Navigate to https://testkru.com/Interactions/Alerts
  2. Click "Show Confirm" and accept the alert
  3. Print the confirm result text

Expected output:

Alert text: Do you want to proceed?
Result: You clicked: OK