TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
Playwright / Chapter 45 of 60~18 min • Beginner
Chapter 45Playwright

Frames and iframes

An iframe embeds a separate document inside a page. Frame locators describe the frame and then locate elements within its document. A locator in the main document does not automatically search inside every iframe.

How it works

Step-by-step walkthrough

  1. Create an iframe
  2. Enter the frame with frameLocator
  3. Assert its heading

Example

TypeScript
import { test, expect } from '@playwright/test';

test('chapter 45 practice', async ({ page }) => {
  await page.setContent('<iframe title="Demo" srcdoc="<h1>Inner page</h1>"></iframe>');
  const frame = page.frameLocator('iframe[title="Demo"]');
  await expect(frame.getByRole('heading')).toHaveText('Inner page');
});
Expected result: Inner page is found
💡 Point to remember
Use a stable frame selector and avoid selecting the first arbitrary frame.

✎ Your practice task

Change the iframe title and update the locator.

Knowledge check

Which API targets content inside an iframe?

🌐 Continue learning