Skip to main content
Glama

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

Implementation Reference

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

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