Skip to main content


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');


Frame locators are strict. This means that all operations on frame locators will throw if more than one element matches a 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();

Converting Locator to FrameLocator

If you have a Locator object pointing to an iframe it can be converted to FrameLocator using :scope CSS selector:

const frameLocator = locator.frameLocator(':scope');


Added in: v1.17

Returns locator to the first matching frame.


Added in: v1.17

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


Added in: v1.17

Returns locator to the last matching frame.

frameLocator.locator(selector[, options])

Added in: v1.17
  • selector <string> A selector to use when resolving DOM element. See working with selectors for more details.#

  • options? <Object>

    • has? <Locator> Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one. For example, article that has text=Playwright matches <article><div>Playwright</div></article>.#

      Note that outer and inner locators must belong to the same frame. Inner locator must not contain FrameLocators.

    • hasText? <string|RegExp> Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a string, matching is case-insensitive and searches for a substring. For example, "Playwright" matches <article><div>Playwright</div></article>.#

  • returns: <Locator>#

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


Added in: v1.17

Returns locator to the n-th matching frame. It's zero based, nth(0) selects the first frame.