getText
Get the text content of an element. Returns null if not found (soft fail).
Signature
const text = await utils.getText(selector, options?)Parameters
| Param | Type | Default | Description |
|---|---|---|---|
selector | string | — | CSS selector or XPath |
options.waitTimeout | number | 0 | Max wait time for element (ms). Default: instant |
options.frame | Frame | — | Optional frame to search within |
Examples
// Instant query
const price = await utils.getText(".price");
if (price) console.log(`Price: ${price}`);
// Wait for element to appear first
const status = await utils.getText("#lazy-status", { waitTimeout: 8000 });
// Returns null if not found
const missing = await utils.getText("#nonexistent"); // → nullError Handling
Soft fail — returns null if element not found. Does not throw.
Last updated on