Skip to content

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

ParameterTypeDescription
ctxContextContext object.
textstringThe visible text to search for.
options?FilterOptionsFilter 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' });

Matterway Assistant SDK Documentation