Back to Puppeteer

Frame.locator() method

website/versioned_docs/version-24.40.0/api/puppeteer.frame.locator.md

19.2.22.0 KB
Original Source

Frame.locator() method

<h2 id="overload-1">locator(): Locator&lt;NodeFor&lt;Selector&gt;&gt;</h2>

Creates a locator for the provided selector. See Locator for details and supported actions.

Signature

typescript
class Frame {
  locator<Selector extends string>(
    selector: Selector,
  ): Locator<NodeFor<Selector>>;
}

Parameters

<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

selector

</td><td>

Selector

</td><td>

selector to query the page for. CSS selectors can be passed as-is and a Puppeteer-specific selector syntax allows querying by text, a11y role and name, and xpath and combining these queries across shadow roots. Alternatively, you can specify the selector type using a prefix.

</td></tr> </tbody></table>

Returns:

Locator<NodeFor<Selector>>

<h2 id="overload-2">locator(): Locator&lt;Ret&gt;</h2>

Creates a locator for the provided function. See Locator for details and supported actions.

Signature

typescript
class Frame {
  locator<Ret>(func: () => Awaitable<Ret>): Locator<Ret>;
}

Parameters

<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

func

</td><td>

() => Awaitable<Ret>

</td><td> </td></tr> </tbody></table>

Returns:

Locator<Ret>