This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest 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
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();
  }
}