k6-docs icon indicating copy to clipboard operation
k6-docs copied to clipboard

Understanding `locator` API

Open ankur22 opened this issue 2 months ago • 0 comments

What

Confusion about when locators are evaluated vs created. For example:

const l = page.locator('#some-id');

is a synchronous API that hasn't interacted with the page yet. It doesn't return an error or do any form of validation at this stage, so if the selector is incorrect you will only find out later when you use a locator method like:

await l.click();

does it actually use the selector #some-id in the locator against the website under test.

Solution

Some details already exist: https://grafana.com/docs/k6/latest/javascript-api/k6-browser/locator/.

Also take a look at the Playwright docs to get a better understanding of what they do and why they're useful.

ankur22 avatar Oct 01 '25 08:10 ankur22