Skip to content

Lupa API Reference / commands/locator / Locator

Class: Locator

Defined in: src/commands/locator.ts:363

A bridge to Playwright's Locator object, used to locate elements on the page and execute actions on them. It uses RPC calls to interact with the Playwright's Page object.

Not all Playwright's Locator actions are supported. Only actions that are relevant to testing are implemented.

Constructors

Constructor

new Locator(query): Locator

Defined in: src/commands/locator.ts:370

Creates a locator.

Parameters

query

LocatorQuery

The query to use to locate the element.

Returns

Locator

A locator.

Methods

blur()

blur(options?): Promise<void>

Defined in: src/commands/locator.ts:389

Calls blur on the element.

Parameters

options?

BlurOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the blur action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ text: 'Focus me' }).blur()

check()

check(options?): Promise<void>

Defined in: src/commands/locator.ts:423

Ensure that checkbox or radio element is checked.

Parameters

options?

CheckOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the check action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ label: 'Subscribe' }).check()

clear()

clear(options?): Promise<void>

Defined in: src/commands/locator.ts:406

Clear the input field.

Parameters

options?

ClearOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the clear action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ label: 'Email' }).clear()

click()

click(options?): Promise<void>

Defined in: src/commands/locator.ts:440

Clicks on the element.

Parameters

options?

ClickOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the click action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ text: 'Submit' }).click()

dblclick()

dblclick(options?): Promise<void>

Defined in: src/commands/locator.ts:475

Double clicks the element.

Parameters

options?

DoubleClickOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the double click action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ text: 'Submit' }).dblclick()

fill()

fill(text, options?): Promise<void>

Defined in: src/commands/locator.ts:458

Fills the input field.

Parameters

text

string

Value to set for the &lt;input&gt;, &lt;textarea&gt; or [contenteditable] element.

options?

FillOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the fill action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ placeholder: 'Username' }).fill('admin')

hover()

hover(options?): Promise<void>

Defined in: src/commands/locator.ts:492

Hovers over the element.

Parameters

options?

HoverOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the hover action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ text: 'Submit' }).hover()

press()

press(key, options?): Promise<void>

Defined in: src/commands/locator.ts:510

Presses the given key.

Parameters

key

string

The key to press.

options?

PressOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the press action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ text: 'Submit' }).press('Enter')

tap()

tap(options?): Promise<void>

Defined in: src/commands/locator.ts:527

Taps the element.

Parameters

options?

TapOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the tap action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ text: 'Submit' }).tap()

uncheck()

uncheck(options?): Promise<void>

Defined in: src/commands/locator.ts:544

Ensure that checkbox or radio element is unchecked.

Parameters

options?

UncheckOptions

Optional settings to modify the action.

Returns

Promise<void>

A promise that resolves when the uncheck action is completed.

Example

typescript
import { query } from '@pawel-up/lupa/commands'

await query({ text: 'Subscribe' }).uncheck()