browser_wait_for_element
Wait for a specific element to appear on a webpage before proceeding with automated browser tasks, ensuring reliable interaction with dynamic content.
Instructions
Wait for an element to appear
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instanceId | Yes | Instance ID | |
| selector | Yes | Element selector | |
| timeout | No | Timeout in milliseconds |
Implementation Reference
- src/tools.ts:935-955 (handler)Core handler function that executes the tool logic: retrieves browser instance and calls Playwright's page.waitForSelector with the given selector and timeout.private async waitForElement(instanceId: string, selector: string, timeout: number): Promise<ToolResult> { const instance = this.browserManager.getInstance(instanceId); if (!instance) { return { success: false, error: `Instance ${instanceId} not found` }; } try { await instance.page.waitForSelector(selector, { timeout }); return { success: true, data: { selector, found: true }, instanceId }; } catch (error) { return { success: false, error: `Wait for element failed: ${error instanceof Error ? error.message : error}`, instanceId }; } }
- src/tools.ts:569-570 (registration)Switch statement case in executeTools method that dispatches to the waitForElement handler.case 'browser_wait_for_element': return await this.waitForElement(args.instanceId, args.selector, args.timeout || 30000);
- src/tools.ts:398-419 (schema)Tool registration in getTools() array, including name, description, and inputSchema for validation.name: 'browser_wait_for_element', description: 'Wait for an element to appear', inputSchema: { type: 'object', properties: { instanceId: { type: 'string', description: 'Instance ID' }, selector: { type: 'string', description: 'Element selector', }, timeout: { type: 'number', description: 'Timeout in milliseconds', default: 30000 } }, required: ['instanceId', 'selector'] } },