BeginnerPW-DLG-00115 minutesPlaywright

Accept a native alert

A native alert blocks the next browser action until it is handled.

  • dialogs
  • events

Objective

What to automate

Accept the alert and verify the visible alert result.

Preconditions and test data

Preconditions

  • Use a fresh isolated Practice Lab browser context.
  • Open the fixture identified by FX-DIALOG-001.

Test data

  • dialog type: alert

Expected result

The page reports that the alert was accepted.

Progressive hints

Hint 1

Register the dialog handler before clicking.

Hint 2

Assert the dialog type or message in the handler.

Hint 3

Check the visible result after accept().

I’ve tried it — show solution
  1. Register the dialog handler before clicking.
  2. Assert the dialog type or message in the handler.
  3. Check the visible result after accept().