Skip to main content
Glama

browser_find_element

Locate web page elements using Selenium WebDriver for browser automation and testing. Specify locator strategies like ID, CSS, or XPath to find elements within a configurable timeout.

Instructions

Find an element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutNoMaximum time to wait for element in milliseconds

Implementation Reference

  • The inline handler function for the browser_find_element tool. It retrieves the WebDriver, instantiates ElementService, calls findElement, and returns a success or error message.
    async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); await elementService.findElement({ by, value, timeout }); return { content: [{ type: 'text', text: 'Element found' }], }; } catch (e) { return { content: [ { type: 'text', text: `Error finding element: ${(e as Error).message}`, }, ], }; } }
  • The registration of the browser_find_element tool using server.tool(), including name, description, input schema, and handler function.
    server.tool( 'browser_find_element', 'Find an element', { ...locatorSchema }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); await elementService.findElement({ by, value, timeout }); return { content: [{ type: 'text', text: 'Element found' }], }; } catch (e) { return { content: [ { type: 'text', text: `Error finding element: ${(e as Error).message}`, }, ], }; } } );
  • The locatorSchema defining the input parameters (by, value, timeout) for element location, used in 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'), };
  • The findElement helper method in ElementService that creates a locator and waits for the element using Selenium WebDriver.
    async findElement(params: LocatorParams): Promise<WebElement> { const locator = LocatorFactory.createLocator(params.by, params.value); return this.driver.wait(until.elementLocated(locator), params.timeout || 15000); }
  • Higher-level registration function that calls registerElementTools, which registers the browser_find_element tool among others.
    export function registerAllTools(server: McpServer, stateManager: StateManager): void { registerBrowserTools(server, stateManager); registerElementTools(server, stateManager); registerActionTools(server, stateManager); registerCookieTools(server, stateManager); }

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