No results for

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

click(selector[, options])

warning

Use locator-based locator.click([options]) instead.

This method clicks on an element matching a selector.

ParameterTypeDefaultDescription
selector
string''A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
options
objectnull

Returns

TypeDescription
Promise<void>An asynchronous operation that doesn't return a value.

Example

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');
await page.click('#counter-button');
}

When a click action results in a page navigation, remember to work with 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/');
await Promise.all([
page.waitForNavigation(),
page.click('a[href="/my_messages.php"]'),
]);
}