Playwright + JS · Lesson 22 of 35

0/35 done

Module 22: Frames, Windows & Popups

22. iFrames, Multi-Tabs & Native JavaScript Dialogs

16 minlesson

Try it yourself

Implement isValidDialogType:

  1. Accept type string.
  2. Return true if type is "alert", "confirm", or "prompt".

The editor has a worked example. Read it, tweak it, then press Mark as complete.

frameLocator API

javascript
// 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();
});

Key Takeaways & Walkthrough Summary

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.

Common Doubts & Lesson Q&A

Does Playwright auto-dismiss JavaScript dialogs by default?

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.

JavaScript
Skip