Skip to content
CodeKruPro

Handle two alerts in a row

Automation taskMediumAsked in: TCS

Asked as: "How do you check whether an alert is present, and handle one that appears after another?" Wait for each alert with the alert-is-present condition before you switch to it, and handle them one at a time.

Handle Sequential Alerts

Handle Sequential Alerts

Sometimes multiple alerts appear one after another. You must handle each one in sequence.

On the Alerts page, clicking "Show Sequential Alerts" triggers two alerts in a row.

Task:

  1. Navigate to https://testkru.com/Interactions/Alerts
  2. Click "Show Sequential Alerts"
  3. Handle the first alert - get text and accept
  4. Handle the second alert - get text and accept
  5. Print both alert texts

Expected output:

Alert 1: This is the first alert!
Alert 2: This is the second alert after the first is closed!