wait_for_element
Waits for a web element to reach a specified state (visible, hidden, attached, detached) using a CSS selector within a defined timeout, ensuring proper web automation and interaction timing.
Instructions
Wait for an element to appear or disappear
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element | |
| state | No | State to wait for | visible |
| timeout | No | Timeout in milliseconds |
Implementation Reference
- src/index.ts:562-581 (handler)Handler for the 'wait_for_element' tool. Parses input using WaitForElementSchema and uses Playwright's page.waitForSelector to wait for the element matching the selector to reach the specified state (default: visible) within the timeout period.case 'wait_for_element': { if (!currentPage) { throw new Error('No browser page available. Launch a browser first.'); } const params = WaitForElementSchema.parse(args); await currentPage.waitForSelector(params.selector, { timeout: params.timeout, state: params.state as any }); return { content: [ { type: 'text', text: `Element ${params.selector} is now ${params.state}` } ] }; }
- src/index.ts:49-53 (schema)Zod schema defining the input parameters for the wait_for_element tool: selector (required CSS selector), timeout (default 30s), state (attached/detached/visible/hidden, default visible).const WaitForElementSchema = z.object({ selector: z.string(), timeout: z.number().default(30000), state: z.enum(['attached', 'detached', 'visible', 'hidden']).default('visible') });
- src/index.ts:256-280 (registration)Tool registration in the ListTools response, including name, description, and inputSchema matching the Zod schema.{ name: 'wait_for_element', description: 'Wait for an element to appear or disappear', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element' }, timeout: { type: 'number', default: 30000, description: 'Timeout in milliseconds' }, state: { type: 'string', enum: ['attached', 'detached', 'visible', 'hidden'], default: 'visible', description: 'State to wait for' } }, required: ['selector'] } },