Skip to main content
Glama

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
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutYesTimeout in milliseconds

Implementation Reference

  • 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}`, }, ], }; } } );
  • 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); }
  • 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'), };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pshivapr/selenium-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server