No results for

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

The Locator API makes it easier to work with dynamically changing elements. Some of the benefits of using it over existing ways to locate an element (e.g. Page.$()) include:

  • Helps with writing robust tests by finding an element even if the underlying frame navigates.
  • Makes it easier to work with dynamic web pages and SPAs built with Svelte, React, Vue, etc.
  • Enables the use of test abstractions like the Page Object Model (POM) pattern to simplify and organize tests.
  • strict mode is enabled for all locator methods, which means that if more than one element matches the given selector it will throw an error.

Locator can be created with the page.locator(selector[, options]) method.

Select the input checkbox.[options])
Mouse click on the chosen element.
Mouse double click on the chosen element.
locator.dispatchEvent(type, eventInit, [options])Dispatches HTML DOM event types e.g. 'click'.
locator.fill(value, [options])Fill an input, textarea or contenteditable element with the provided value.
locator.focus([options])Calls focus on the element, if it can be focused.
locator.getAttribute(name, [options])Returns the element attribute value for the given attribute name.
Hovers over the element.
locator.innerHTML([options])Returns the element.innerHTML.
locator.innerText([options])Returns the element.innerText.
locator.inputValue([options])Returns input.value for the selected input, textarea or select element.
locator.isChecked([options])Checks if the checkbox input type is selected.
locator.isDisabled([options])Checks if the element is disabled.
locator.isEditable([options])Checks if the element is editable.
locator.isEnabled([options])Checks if the element is enabled.
locator.isHidden([options])Checks if the element is hidden.
locator.isVisible([options])Checks if the element is visible., [options])Press a single key on the keyboard or a combination of keys.
locator.selectOption(values, [options])
Select one or more options which match the values.
Tap on the chosen element.
locator.textContent([options])Returns the element.textContent.
locator.type(text, [options])Type in the text into the input field.
Unselect the input checkbox.
Wait for the element to be in a particular state e.g. visible.


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();
try {
await page.goto("")
In this example, we will use two locators, matching a
different betting button on the page. If you were to query
the buttons once and save them as below, you would see an
error after the initial navigation. Try it!
const heads = page.$("input[value='Bet on heads!']");
const tails = page.$("input[value='Bet on tails!']");
The Locator API allows you to get a fresh element handle each
time you use one of the locator methods. And, you can carry a
locator across frame navigations. Let's create two locators;
each locates a button on the page.
const heads = page.locator("input[value='Bet on heads!']");
const tails = page.locator("input[value='Bet on tails!']");
const currentBet = page.locator("//p[starts-with(text(),'Your bet: ')]");
// In the following Promise.all the tails locator clicks
// on the tails button by using the locator's selector.
// Since clicking on each button causes page navigation,
// waitForNavigation is needed -- this is because the page
// won't be ready until the navigation completes.
// Setting up the waitForNavigation first before the click
// is important to avoid race conditions.
await Promise.all([
// the heads locator clicks on the heads button
// by using the locator's selector.
await Promise.all([
await Promise.all([
} finally {