Back to Puppeteer

Frame.$() method

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

19.2.21.5 KB
Original Source

Frame.$() method

Queries the frame for an element matching the given selector.

Signature

typescript
class Frame {
  $<Selector extends string>(
    selector: Selector,
  ): Promise<ElementHandle<NodeFor<Selector>> | null>;
}

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:

Promise<ElementHandle<NodeFor<Selector>> | null>

A element handle to the first element matching the given selector. Otherwise, null.