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.
Returns
Example
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();
}
}

