Skip to content

Function: waitForSelector()

ts
function waitForSelector(
   ctx: Context, 
   selector: string, 
options?: WaitForSelectorOptions): Promise<ElementHandle<Element> | null>;

Defined in: src/wait/waiters/waitForSelector.ts:53

Wait for a selector to appear on the page.

Parameters

ParameterTypeDescription
ctxContextContext object.
selectorstringCSS or XPath selector to wait for.
options?WaitForSelectorOptionsWait for selector options.

Returns

Promise<ElementHandle<Element> | null>

The matched element handle, or null for negative XPath conditions.

Example

ts
// Wait for the big red "Buy Now" button
await waitForSelector(ctx, '#buy-now-btn');

// XPath works too
await waitForSelector(ctx, '//button[text()="Add to Cart"]');

Matterway Assistant SDK Documentation