browser_wait_for_element
Waits for a web element to appear on a page using specified locator strategy and timeout, enabling reliable automation of dynamic content interactions.
Instructions
Wait for an element to be present
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| value | Yes | Value for the locator strategy | |
| timeout | Yes | Timeout in milliseconds |
Implementation Reference
- src/tools/actionTools.ts:33-59 (registration)Registers the browser_wait_for_element MCP tool, including input schema (locator + timeout) and thin handler that delegates to ActionService.waitForElement after getting driver from stateManager.server.tool( '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 (handler)Core implementation of waiting for element: uses LocatorFactory to create Selenium locator and driver.wait with until.elementLocated.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)locatorSchema defines the base input parameters (by, value, optional timeout) using Zod, spread into the tool schema.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'), };