lecture 15 of 220 completed

Browser dialogs: alert, confirm and prompt

A native dialog is not part of the page. Your selectors cannot see it, and an unhandled one blocks everything after it.

What you'll learn

  • Why a browser dialog cannot be found with a selector
  • How to read, accept and dismiss one
  • Why an unhandled dialog breaks everything after it

Your test clicks Delete. A confirmation box appears asking "Are you sure?". Your next line looks for the updated table and fails with a message about the element not being found, or about an unexpected alert being open.

The dialog is not part of the page. It is drawn by the browser, outside the DOM. No CSS selector can reach it, and while it is open the page underneath is frozen.

Three kinds exist, and they behave differently:

alert shows a message with one OK button.

confirm asks a question with OK and Cancel. Your choice changes what the app does, so both paths are worth testing.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →