[Go to site: main page, start]

Skip to content

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.

js
$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.

js
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');
OptionDefaultDescription
tabCount1Number of Tab presses after typing.
sleep500Delay (ms) between clearing and typing, and after tab.
speedkeyboard speedTyping delay per character (ms).
modereplacereplace, append, or prepend the value.
timeout30000Max time (ms) to wait for the selector.
continueOnErrorfalseReturn without throwing if the element is not found.
visibleOnlyfalseOnly consider visible elements.
index0Pick 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.

js
await $clickElement('#comment');
await $keyboardPress('Hello there');

// Focus a field first, then type slowly
await $keyboardPress('user@example.com', { selector: '#email', speed: 60 });
OptionDefaultDescription
selectornullCSS selector to focus before typing. Leave empty to type into the focused element.
speedkeyboard speedTyping delay per character (ms). 0 types instantly.
timeout30000Max time (ms) to wait for the selector.
continueOnErrorfalseReturn without throwing if the selector is not found.
visibleOnlyfalseOnly consider visible elements.
index0Pick 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.

js
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 });
OptionDefaultDescription
cmdOrCtrlfalseHold the platform shortcut key (Cmd on macOS, Ctrl elsewhere).
controlfalseHold Ctrl.
metafalseHold Meta (Cmd on macOS, Windows key elsewhere).
shiftfalseHold Shift.
altfalseHold Alt (Option on macOS).
repeat1Number of times to press the shortcut.

Clicking ​

$clickElement(selectorOrHandle, options?) ​

Click an element after an optional delay. Accepts a CSS selector or ElementHandle.

js
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 });
OptionDefaultDescription
delay1000Delay (ms) before and after clicking.
buttonTypeleftMouse button: left, middle, or right.
offsetX0Horizontal 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.
offsetY0Vertical shift (px) from the element center. Negative values move up.
continueOnErrorfalseReturn null instead of throwing if the element is not found.
timeout30000Max time (ms) to wait for the selector.
textMatchnullText to match against each candidate's visible text.
textFiltercontainsMatch mode: contains, exact, startsWith, or endsWith.
textCaseSensitivefalsePreserve letter casing when matching text.
visibleOnlyfalseOnly 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.

js
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.

js
await $clickAtCoordinates(320, 240);
await $clickAtCoordinates(320, 240, { buttonType: 'right', delay: 250 });
OptionDefaultDescription
delay1000Delay (ms) before and after clicking.
buttonTypeleftMouse 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.

js
await $scrollByPixels(500);
await $scrollByPixels(-300);

$scrollToElement(selectorOrHandle) ​

Scroll the page or its nearest scrollable container until an element is visible.

js
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:

css
#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:

css
[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:

css
[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:

js
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).

js
const el = await $selectOneElement('.btn-primary');
const confirmBtn = await $selectOneElement('button', { textMatch: 'Confirm', textFilter: 'exact', visibleOnly: true });
const third = await $selectOneElement('.item', { index: 2 });
OptionDefaultDescription
textMatchnullText to match against each candidate's visible text.
textFiltercontainsMatch mode: contains, exact, startsWith, or endsWith.
textCaseSensitivefalsePreserve letter casing when matching text.
visibleOnlyfalseOnly return visible elements.
index0Pick the nth matching element. Negative values count from the end.
timeout30000Max 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.

js
const rows = await $selectManyElements('table tr');
const visibleButtons = await $selectManyElements('button', {
  textMatch: 'Download',
  textFilter: 'startsWith',
  visibleOnly: true,
});
OptionDefaultDescription
textMatchnullText to match against each candidate's visible text.
textFiltercontainsMatch mode: contains, exact, startsWith, or endsWith.
textCaseSensitivefalsePreserve letter casing when matching text.
visibleOnlyfalseOnly return visible elements.
timeout30000Max 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).

js
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.

js
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).

js
await $waitForSelectorCondition(
  '.status',
  (el) => el.textContent.includes('Complete'),
  { timeout: 15000 }
);
OptionDefaultDescription
timeout10000Max 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.

js
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.

js
await $shadowInputFill('#shadow-input', 'value', {
  rootSelector: '#shadow-host',
  speed: 50,
});

Accepts mode, tabCount, sleep, speed, continueOnError, visibleOnly, and index, plus:

OptionDefaultDescription
rootSelectornullCSS selector for the shadow host root to start searching from.
timeout5000Max time (ms) to wait for the selector.