No results for

Powered byAlgolia
⚠️ This documentation is outdated. Please visit grafana.com for the latest k6 documentation.📚

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 { chromium } from 'k6/experimental/browser';
export default async function () {
const browser = chromium.launch();
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 { chromium } from 'k6/experimental/browser';
export default async function () {
const browser = chromium.launch();
const page = browser.newPage();
await page.goto('https://test.k6.io/');
await Promise.all([
page.waitForNavigation(),
page.click('a[href="/my_messages.php"]'),
]);
}