Back to Puppeteer

Page.type() method

docs/api/puppeteer.page.type.md

19.2.21.9 KB
Original Source

Page.type() method

Sends a keydown, keypress/input, and keyup event for each character in the text.

To press a special key, like Control or ArrowDown, use Keyboard.press().

Signature

typescript
class Page {
  type(
    selector: string,
    text: string,
    options?: Readonly<KeyboardTypeOptions>,
  ): Promise<void>;
}

Parameters

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

Parameter

</th><th>

Type

</th><th>

Description

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

selector

</td><td>

string

</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> <tr><td>

text

</td><td>

string

</td><td>

A text to type into a focused element.

</td></tr> <tr><td>

options

</td><td>

Readonly<KeyboardTypeOptions>

</td><td>

(Optional) have property delay which is the Time to wait between key presses in milliseconds. Defaults to 0.

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

Returns:

Promise<void>

Example

ts
await page.type('#mytextarea', 'Hello');
// Types instantly
await page.type('#mytextarea', 'World', {delay: 100});
// Types slower, like a user