Playwright + JS · Lesson 22 of 35
Module 22: Frames, Windows & Popups
Try it yourself
Implement isValidDialogType:
The editor has a worked example. Read it, tweak it, then press Mark as complete.
frameLocator API// Locate elements directly inside an iframe:
const paymentFrame = page.frameLocator("#stripe-payment-frame");
await paymentFrame.getByLabel("Card Number").fill("4242 4242 4242 4242");
// Multi-tabs:
const pagePromise = context.waitForEvent("page");
await page.getByRole("link", { name: "Open Terms" }).click();
const newPage = await pagePromise;
await expect(newPage).toHaveTitle(/Terms of Service/);
// Dialogs:
page.on("dialog", async (dialog) => {
await dialog.accept();
});Handling iframes and multiple tabs used to be a major pain point in older tools. In Playwright, frameLocator makes interacting with iframes seamless without manual context switching. In this lesson, we will cover iframes, nested frames, new browser tabs, and native alert dialogs. Let's explore!
Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Yes! Playwright automatically dismisses native dialogs so tests do not hang unless you register a page.on('dialog') handler.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.