Skip to main content
Version: 1.17

FrameLocator

FrameLocator represents a view to the iframe on the page. It captures the logic sufficient to retrieve the iframe and locate elements in that iframe. FrameLocator can be created with either page.frameLocator(selector) or locator.frameLocator(selector) method.

const locator = page.frameLocator('#my-frame').locator('text=Submit');
await locator.click();

Strictness

Frame locators are strict. This means that all operations on frame locators will throw if more than one element matches given selector.

// Throws if there are several frames in DOM:
await page.frameLocator('.result-frame').locator('button').click();

// Works because we explicitly tell locator to pick the first frame:
await page.frameLocator('.result-frame').first().locator('button').click();

frameLocator.first()

Returns locator to the first matching frame.

frameLocator.frameLocator(selector)

When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.

frameLocator.last()

Returns locator to the last matching frame.

frameLocator.locator(selector)

The method finds an element matching the specified selector in the FrameLocator's subtree.

frameLocator.nth(index)

Returns locator to the n-th matching frame.