Working inside a frame

Page locators stop at the frame

page.getByRole(), getByText() and the others search the page's own document only. Get a locator for the frame's document, then locate inside it:

const frame = page.getByTitle('Embedded Form').contentFrame();

await frame.getByLabel('Name').fill('Ada');
await frame.getByRole('button', { name: 'Submit' }).click();

await expect(frame.getByRole('status')).toHaveText('Hello, Ada');
await expect(page.getByText('Hello, Ada')).toHaveCount(0); // not in the page

contentFrame() or frameLocator()?

They return the same thing, a FrameLocator. contentFrame() starts from any locator for the <iframe> element, so you can find the frame by its title, role or surroundings. frameLocator() takes a CSS selector:

page.getByTitle('Newsletter signup').contentFrame();
page.frameLocator('iframe[title="Newsletter signup"]'); // same frame

The element and the document are different things

Attributes such as src and title belong to the <iframe> element in the page. Assert them on the element. owner() takes you from a frame back to its element:

const newsletter = page.frameLocator('iframe[title="Newsletter signup"]');

await expect(newsletter.owner()).toHaveAttribute('src', '/embeds/newsletter/');
Frame locators auto-wait like any other locator: if the frame is still loading, Playwright waits for the element inside it.

Embedded form

This form is an inline document (srcdoc) inside an iframe.

Newsletter

This frame loads its own page by URL, like most third-party widgets.