Appearance
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
| Parameter | Type | Description |
|---|---|---|
ctx | Context | Context object. |
selector | string | CSS or XPath selector to wait for. |
options? | WaitForSelectorOptions | Wait 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"]');