Handle Alert Dialog
In Playwright, dialogs are handled via event listeners. Register a handler with page.on('dialog', handler) before the action that triggers the dialog.
dialog.accept() clicks OK, dialog.dismiss() clicks Cancel.
On the Alerts page, clicking "Show Alert" triggers a simple alert.
Task:
- Navigate to
https://testkru.com/Interactions/Alerts - Set up a dialog handler that prints the message and accepts
- Click the "Show Alert" button
Expected output:
Dialog message: This is a simple alert! Dialog accepted
TestKru