Appearance
Function: getElementByText()
ts
function getElementByText(
ctx: Context,
text: string,
options?: FilterOptions): Promise<ElementHandle<Element> | null>;Defined in: src/dom/index.ts:135
Return an element that contains the given text.
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context | Context object. |
text | string | The visible text to search for. |
options? | FilterOptions | Filter options to narrow the element match. |
Returns
Promise<ElementHandle<Element> | null>
The matching element handle.
Examples
ts
// Find and grab the "Place Order" button by its label
const orderBtn = await getElementByText(ctx, 'Place Order');ts
// Narrow the search to div elements only
const label = await getElementByText(ctx, 'Shipping Address', { filterElementWithTag: 'div' });