Interaction & Selectors
Click, type, scroll, and query elements. Most functions accept either a CSS selector string or a Puppeteer ElementHandle.
Typing
$keyboardSpeed(milliseconds)
Set the default delay between keystrokes for subsequent input actions.
$keyboardSpeed(35);
await $fillInput('#search', 'Puppetflow');Returns the configured delay in milliseconds.
$fillInput(selector, value, options?)
Replace, append, or prepend an input value with realistic timing. Handles detached-node retries automatically.
await $fillInput('#email', 'user@example.com');
await $fillInput('#search', 'query', { speed: 50, sleep: 200, tabCount: 0 });
// Works with an ElementHandle too
const input = await $page.$('#name');
await $fillInput(input, 'Alice');| Option | Default | Description |
|---|---|---|
tabCount | 1 | Number of Tab presses after typing. |
sleep | 500 | Delay (ms) between clearing and typing, and after tab. |
speed | keyboard speed | Typing delay per character (ms). |
mode | replace | replace, append, or prepend the value. |
timeout | 30000 | Max time (ms) to wait for the selector. |
continueOnError | false | Return without throwing if the element is not found. |
visibleOnly | false | Only consider visible elements. |
index | 0 | Pick the nth matching element. |
$keyboardPress(text, options?)
Type text one keystroke at a time into whatever currently has focus, or into an element focused first through options.selector. Unlike $fillInput, nothing is cleared beforehand. A newline in the text presses Enter.
await $clickElement('#comment');
await $keyboardPress('Hello there');
// Focus a field first, then type slowly
await $keyboardPress('user@example.com', { selector: '#email', speed: 60 });| Option | Default | Description |
|---|---|---|
selector | null | CSS selector to focus before typing. Leave empty to type into the focused element. |
speed | keyboard speed | Typing delay per character (ms). 0 types instantly. |
timeout | 30000 | Max time (ms) to wait for the selector. |
continueOnError | false | Return without throwing if the selector is not found. |
visibleOnly | false | Only consider visible elements. |
index | 0 | Pick the nth matching element. |
$keyboardShortcut(key, options?)
Press one key while holding modifiers. key is a single character or a key name such as Enter, Tab, Escape, ArrowDown or F5. cmdOrCtrl holds Cmd on macOS and Ctrl elsewhere, so the same flow works on both.
await $keyboardShortcut('a', { cmdOrCtrl: true }); // select all
await $keyboardShortcut('Enter', { shift: true }); // soft line break
await $keyboardShortcut('Tab', { repeat: 3 }); // move focus three fields ahead
await $keyboardShortcut('s', { control: true, shift: true });| Option | Default | Description |
|---|---|---|
cmdOrCtrl | false | Hold the platform shortcut key (Cmd on macOS, Ctrl elsewhere). |
control | false | Hold Ctrl. |
meta | false | Hold Meta (Cmd on macOS, Windows key elsewhere). |
shift | false | Hold Shift. |
alt | false | Hold Alt (Option on macOS). |
repeat | 1 | Number of times to press the shortcut. |
Clicking
$clickElement(selectorOrHandle, options?)
Click an element after an optional delay. Accepts a CSS selector or ElementHandle.
await $clickElement('#submit');
await $clickElement('.next-btn', { delay: 2000 });
await $clickElement('.optional', { continueOnError: true });
await $clickElement('button', { textMatch: 'Confirm', textFilter: 'exact', visibleOnly: true });
await $clickElement('.context-menu-target', { buttonType: 'right' });
// Click 40px to the right of the element center (e.g. an icon drawn next to it)
await $clickElement('.row-label', { offsetX: 40, offsetY: 0 });| Option | Default | Description |
|---|---|---|
delay | 1000 | Delay (ms) before and after clicking. |
buttonType | left | Mouse button: left, middle, or right. |
offsetX | 0 | Horizontal shift (px) from the element center. When offsetX or offsetY is non-zero, the click is sent to that shifted point instead of the element itself. Negative values move left. |
offsetY | 0 | Vertical shift (px) from the element center. Negative values move up. |
continueOnError | false | Return null instead of throwing if the element is not found. |
timeout | 30000 | Max time (ms) to wait for the selector. |
textMatch | null | Text to match against each candidate's visible text. |
textFilter | contains | Match mode: contains, exact, startsWith, or endsWith. |
textCaseSensitive | false | Preserve letter casing when matching text. |
visibleOnly | false | Only consider visible elements. |
$clickElementAtIndex(selector, index, options?)
Click the nth element matching a selector. Indexes are zero-based; negative values count from the end (-1 is the last match). Same options as $clickElement, except offsetX and offsetY.
await $clickElementAtIndex('.list-item button', 2);
await $clickElementAtIndex('.tab', 0, { textMatch: 'Overview', textFilter: 'exact' });$clickAtCoordinates(x, y, options?)
Click viewport coordinates directly. This bypasses selector resolution.
await $clickAtCoordinates(320, 240);
await $clickAtCoordinates(320, 240, { buttonType: 'right', delay: 250 });| Option | Default | Description |
|---|---|---|
delay | 1000 | Delay (ms) before and after clicking. |
buttonType | left | Mouse button: left, middle, or right. |
Scrolling
$scrollByPixels(amount)
Scroll the page vertically by an exact pixel amount. Positive values scroll down and negative values scroll up.
await $scrollByPixels(500);
await $scrollByPixels(-300);$scrollToElement(selectorOrHandle)
Scroll the page or its nearest scrollable container until an element is visible.
await $scrollToElement('#checkout');
const element = await $selectOneElement('.active-row');
await $scrollToElement(element);Selectors
Writing a selector
Every selector field accepts standard CSS selector syntax. Prefer stable attributes that describe the element when they are available:
#submit
.primary-button
button[type="submit"]
[data-testid="employees-tab"]
nav [aria-label="Employees"]Combine selectors to narrow the result. A space selects a descendant, while writing selectors without a space applies every condition to the same element:
[class*="Tabs_tab__"] span
button[class*="Button_root__"][type="submit"]Attribute selectors are useful when a site adds a generated value to a class or another attribute:
[class^="Tabs_"] /* starts with */
[class$="_active"] /* ends with */
[class*="Tabs_tab__"] /* contains */For example, [class*="Tabs_tab__"] span finds span elements below an element whose class attribute contains Tabs_tab__. Attribute values and class names are case-sensitive, so Tabs_tab__ and tabs_tab__ are different.
Use the selector to identify candidate elements, then use textMatch when the desired element is distinguished by its visible text:
await $clickElement('[class*="Tabs_tab__"] span', {
textMatch: 'Employees List',
textFilter: 'contains',
});In a nodal flow, enter the same CSS selector in the selector field and use the Text and Text condition fields for visible-text matching.
$selectOneElement(selectorOrHandle, options?)
Get an ElementHandle matching a selector with optional filtering. Returns null if not found (never throws).
const el = await $selectOneElement('.btn-primary');
const confirmBtn = await $selectOneElement('button', { textMatch: 'Confirm', textFilter: 'exact', visibleOnly: true });
const third = await $selectOneElement('.item', { index: 2 });| Option | Default | Description |
|---|---|---|
textMatch | null | Text to match against each candidate's visible text. |
textFilter | contains | Match mode: contains, exact, startsWith, or endsWith. |
textCaseSensitive | false | Preserve letter casing when matching text. |
visibleOnly | false | Only return visible elements. |
index | 0 | Pick the nth matching element. Negative values count from the end. |
timeout | 30000 | Max time (ms) to wait for the selector. |
$selectManyElements(selector, options?)
Get all ElementHandles matching a selector with optional filtering. Returns an empty array if none are found.
const rows = await $selectManyElements('table tr');
const visibleButtons = await $selectManyElements('button', {
textMatch: 'Download',
textFilter: 'startsWith',
visibleOnly: true,
});| Option | Default | Description |
|---|---|---|
textMatch | null | Text to match against each candidate's visible text. |
textFilter | contains | Match mode: contains, exact, startsWith, or endsWith. |
textCaseSensitive | false | Preserve letter casing when matching text. |
visibleOnly | false | Only return visible elements. |
timeout | 30000 | Max time (ms) to wait for the selector. |
$attributesFromOne(selectorOrHandle, getters, options?)
Extract named, JSON-compatible values from one element. Map each output key to a getter. Returns null if no element matches. Accepts the same options as $selectOneElement (textMatch, textFilter, textCaseSensitive, visibleOnly, index, timeout).
const product = await $attributesFromOne('.product', {
title: 'textContent',
sku: 'attribute:data-sku',
link: 'href',
});
const secondPrice = await $attributesFromOne('.price', { value: 'innerText' }, { index: 1, visibleOnly: true });Common getters include textContent, innerText, value, href, src, className, id, tagName, outerHTML, innerHTML, and attribute:name.
$attributesFromMany(selectorOrHandle, getters, options?)
Apply the same getters to every matching element. The helper returns an array of objects, or an empty array when nothing matches.
The first argument can be a selector, one ElementHandle, or an array of handles. It accepts the same options as $selectManyElements: textMatch, textFilter, textCaseSensitive, visibleOnly, and timeout.
const products = await $attributesFromMany('.product', {
title: 'innerText',
sku: 'attribute:data-sku',
});
const visibleLinks = await $attributesFromMany('a', { href: 'href' }, { visibleOnly: true });$waitForSelectorCondition(selector, condition, options?)
Wait for at least one element matching selector to satisfy a condition function (evaluated in the page context).
await $waitForSelectorCondition(
'.status',
(el) => el.textContent.includes('Complete'),
{ timeout: 15000 }
);| Option | Default | Description |
|---|---|---|
timeout | 10000 | Max time (ms) to wait. |
Selector-based helpers support deep selectors: use >>> to cross an open shadow root and >>iframe>> to cross an iframe boundary. Deep selectors use a 5-second default timeout when no timeout is supplied.
Shadow DOM
$selectShadow(selector, rootSelector?, options?)
Find an element inside open shadow DOM roots. Recursively traverses shadow roots to find the first match.
const el = await $selectShadow('input.inner');
const el2 = await $selectShadow('span.label', '#host-element');Returns an ElementHandle or null.
Options include timeout (default 5000), continueOnError (default true), text matching, visibleOnly, and index.
$shadowInputFill(selector, value, options?)
Fill an input located inside shadow DOM. Combines $selectShadow + $fillInput.
await $shadowInputFill('#shadow-input', 'value', {
rootSelector: '#shadow-host',
speed: 50,
});Accepts mode, tabCount, sleep, speed, continueOnError, visibleOnly, and index, plus:
| Option | Default | Description |
|---|---|---|
rootSelector | null | CSS selector for the shadow host root to start searching from. |
timeout | 5000 | Max time (ms) to wait for the selector. |
