Skip to main content
Version: 23.6.1

Locator class

Locators describe a strategy of locating objects and performing an action on them. If the action fails because the object is not ready for the action, the whole operation is retried. Various preconditions for a successful action are checked automatically.

See https://pptr.dev/guides/page-interactions#locators for details.

Signature

export declare abstract class Locator<T> extends EventEmitter<LocatorEvents>

Extends: EventEmitter<LocatorEvents>

Properties

Property

Modifiers

Type

Description

_

optional

T

Used for nominally typing Locator.

timeout

readonly

number

Methods

Method

Modifiers

Description

click(this, options)

Clicks the located element.

clone()

Clones the locator.

fill(this, value, options)

Fills out the input identified by the locator using the provided value. The type of the input is determined at runtime and the appropriate fill-out method is chosen based on the type. contenteditable, select, textarea and input elements are supported.

filter(predicate)

Creates an expectation that is evaluated against located values.

If the expectations do not match, then the locator will retry.

hover(this, options)

Hovers over the located element.

map(mapper)

Maps the locator using the provided mapper.

race(locators)

static

Creates a race between multiple locators trying to locate elements in parallel but ensures that only a single element receives the action.

scroll(this, options)

Scrolls the located element.

setEnsureElementIsInTheViewport(this, value)

Creates a new locator instance by cloning the current locator and specifying whether the locator should scroll the element into viewport if it is not in the viewport already.

setTimeout(timeout)

Creates a new locator instance by cloning the current locator and setting the total timeout for the locator actions.

Pass 0 to disable timeout.

setVisibility(this, visibility)

Creates a new locator instance by cloning the current locator with the visibility property changed to the specified value.

setWaitForEnabled(this, value)

Creates a new locator instance by cloning the current locator and specifying whether to wait for input elements to become enabled before the action. Applicable to click and fill actions.

setWaitForStableBoundingBox(this, value)

Creates a new locator instance by cloning the current locator and specifying whether the locator has to wait for the element's bounding box to be same between two consecutive animation frames.

wait(options)

Waits for the locator to get the serialized value from the page.

Note this requires the value to be JSON-serializable.

waitHandle(options)

Waits for the locator to get a handle from the page.