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 a nested iframe that matches the given selector within this frame. Use this to chain frame locators for nested iframes.

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

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.setContent(`
      <iframe id="outer" srcdoc="<iframe id='inner' srcdoc='<button>Submit</button>'></iframe>"></iframe>
    `);

    // Nested iframes: outer frame, then inner frame, then element
    const button = page.frameLocator('#outer').frameLocator('#inner').locator('button');
    await button.click();
  } finally {
    await page.close();
  }
}