browser_wait_for_element
Wait for a web element to appear on the page using specified locator strategy and timeout, ensuring reliable automation of browser interactions.
Instructions
Wait for an element to be present
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| timeout | Yes | Timeout in milliseconds | |
| value | Yes | Value for the locator strategy |
Implementation Reference
- src/tools/actionTools.ts:34-58 (registration)Registers the browser_wait_for_element MCP tool, providing name, description, input schema (extending locatorSchema with timeout), and the handler function that uses ActionService to wait for the element.'browser_wait_for_element', 'Wait for an element to be present', { ...locatorSchema, timeout: z.number().describe('Timeout in milliseconds'), }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.waitForElement({ by, value, timeout }); return { content: [{ type: 'text', text: `Waited for element: ${value}` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error waiting for element: ${(e as Error).message}`, }, ], }; } }
- src/services/actionService.ts:16-19 (helper)Implements the core waiting logic for an element using Selenium WebDriver's until.elementLocated with dynamic locator.async waitForElement(params: LocatorParams): Promise<WebElement> { const locator = LocatorFactory.createLocator(params.by, params.value); return this.driver.wait(until.elementLocated(locator), params.timeout || 15000); }
- src/types/index.ts:29-35 (schema)Defines the base locatorSchema Zod object used in the tool's input schema for 'by', 'value', and optional 'timeout'.export const locatorSchema = { by: z .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink']) .describe('Locator strategy to find element'), value: z.string().describe('Value for the locator strategy'), timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'), };