Back to Puppeteer

Page.$() method

docs/api/puppeteer.page._.md

19.2.21.5 KB
Original Source

Page.$() method

Finds the first element that matches the selector. If no element matches the selector, the return value resolves to null.

Signature

typescript
class Page {
  $<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>

Remarks

Shortcut for Page.mainFrame().$(selector).