Menu
Open source
isInViewport([options])
Checks whether the element intersects the browser viewport. This matches Playwright’s toBeInViewport semantics.
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();
await page.goto('https://test.k6.io/');
const button = page.locator('button#submit');
if (await button.isInViewport()) {
await button.click();
}
}