Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

frameLocator(selector)

Returns a FrameLocator for the iframe that matches the given selector within this frame. Use this to interact with elements inside nested iframes.

ParameterTypeDescription
selectorstringA selector that resolves to an iframe element (for example iframe#payment or iframe[name="form"]).

Returns

TypeDescription
FrameLocatorA FrameLocator for the matched nested iframe.

Example

JavaScript
import { browser } from 'k6/browser';

export const options = {
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.goto('https://example.com/page-with-nested-iframes');

    // Get the outer frame, then locate a nested iframe inside it
    const mainFrame = page.mainFrame();
    const innerFrame = mainFrame.frameLocator('iframe#inner');
    await innerFrame.locator('button').click();
  } finally {
    await page.close();
  }
}