No results for

Powered byAlgolia
⚠️ This is the archived documentation for k6 v0.47. Go to the latest version.

click([options])

attention

This method has known issues. For details, refer to #471 and #474.

Mouse click on the chosen element.

ParameterTypeDefaultDescription
options
objectnull

Examples

Click action without navigation
import { browser } from 'k6/experimental/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}
export default async function () {
const page = browser.newPage();
await page.goto('https://test.k6.io/browser.php');
const button = page.locator('#counter-button');
await button.click();
}

When a click action results in a page navigation, remember to work with Promise.all() and page.waitForNavigation() to properly handle the asynchronous operation.

Click action with navigation
import { browser } from 'k6/experimental/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}
export default async function () {
const page = browser.newPage();
await page.goto('https://test.k6.io/');
const messagesLink = page.locator('a[href="/my_messages.php"]');
await Promise.all([page.waitForNavigation(), messagesLink.click()]);
}