wait_for_element
Monitors web elements for specific states (attached, detached, visible, hidden) using CSS selectors, ensuring synchronization in browser automation workflows within AutoProbeMCP.
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)The main handler function for the 'wait_for_element' tool. It validates input using WaitForElementSchema, waits for the specified selector using Playwright's waitForSelector with timeout and state, and returns a success message.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 string), timeout (default 30000ms), state (enum with 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'] } },