k6/browser adds frameLocator()
Introduced 2026-02-10 · score 0.98
HOW TO USE IT
When a k6 browser test needs to interact with iframe content, call `frameLocator(selector)` with a selector that resolves to the iframe. Chain another `frameLocator()` for nested frames, then use `locator()` to target and interact with elements inside.
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('<URL>');
const frame = page.frameLocator('<iframe-selector>');
await frame.locator('<element-selector>').click();
const nested = page.frameLocator('<outer-iframe-selector>')
.frameLocator('<inner-iframe-selector>');
await nested.locator('<nested-element-selector>').click();
} finally {
await page.close();
}
}WHY THIS HELPS
Interact with elements inside an iframe while testing a web application with k6 browser.
REQUIREMENTS AND LIMITATIONS
- Version: v1.6.0
- selector (required): String selector that resolves to an iframe element; used by `frameLocator(selector)` to return a FrameLocator for that iframe.
- Prerequisite: Configure a browser scenario with a browser type such as `chromium` and import `browser` from `k6/browser`.
FIRST-PARTY EVIDENCE
- https://github.com/grafana/k6/releases/tag/v1.6.0
- https://grafana.com/docs/k6/latest/javascript-api/k6-browser/locator/framelocator/
Check the installed version and the source before using it. Entry JSON