Manuals / Playwright with Python / Chapter 17

Part 2 · Core Interactions · intermediate · ~35 min · Chapter 17 of 61

11. Alerts, Dialogs, Popups

page.on("dialog", lambda dialog: dialog.accept()) page.get_by_role("button", name="Delete account").click() # triggers confirm() Native browser dialogs (alert(), confirm(), prompt()) block all further JavaScript execution until dismissed. You must register a handler before triggering the action that opens the dialog — if you forget, the dialog blocks the page indefinitely and your test times out w

Path progress
27%

Step 1 of 4

Overview

Native browser dialogs (alert(), confirm(), prompt()) block all further JavaScript execution until dismissed. You must register a handler before triggering the action that opens the dialog — if you forget, the dialog blocks the page indefinitely and your test times out waiting.

OverviewDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Page under testdrag · tap →Multi-browserdrag · tap →Automation pathdrag · tap →Tooling nodedrag · tap →

Try it

Run / study this snippet

page.on("dialog", lambda dialog: dialog.accept())
Was this step clear?
Chapter learning outcomes
  • page.on("dialog", lambda dialog: dialog.accept()) page.get_by_role("button", nam
  • You must register a handler before triggering the action that opens the dialog —

Clear these before you leave

Side quest

11. Alerts, Dialogs, Popups deliverable

Apply one idea from “Overview” in a small script or note.