Playwright + Java · Lesson 23 of 38
Module 23: Windows, Tabs & Popups
Your task
Implement acceptNextDialog:
Write it in the editor, then press Check answer (Ctrl + Enter).
Page newTab = page.waitForPage(() -> {
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Terms of Service")).click();
});
page.onDialog(dialog -> {
dialog.accept();
});Web apps frequently open external links in new browser tabs and prompt users with native alert dialogs. In this lesson, you will learn how to capture new tabs using waitForPage and handle browser dialogs with onDialog listeners. Let's master multi-window automation!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Playwright automatically dismisses native alerts unless you register an explicit page.onDialog() listener before triggering the event.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___