Playwright + Python · Lesson 22 of 37
Module 22: Windows, Tabs & Popups
Your task
Implement accept_all_dialogs(page):
Write it in the editor, then press Check answer (Ctrl + Enter).
expect_page()with page.expect_page() as new_tab_info:
page.get_by_role("link", name="Privacy Policy").click()
new_tab = new_tab_info.value
new_tab.wait_for_load_state()
new_tab.close()
page.on("dialog", lambda dialog: dialog.accept())Handling popups and external links that open in new tabs is seamless with Playwright. In this lesson, you will capture new pages with expect_page() and handle alerts using on_dialog listeners. Let's master multi-window automation!
Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Playwright auto-dismisses alerts by default so test suites never freeze waiting for user input on CI.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___