Skip to main content
Glama

browser_find_element

Locate web page elements using various strategies like ID, CSS, XPath, or class name to enable automated browser interaction and testing.

Instructions

Find an element

Input Schema

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

Implementation Reference

  • MCP tool handler implementation for 'browser_find_element'. It retrieves the WebDriver from state, instantiates ElementService, calls findElement, and returns a textual response indicating success or error.
    '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}`, }, ], }; } } );
  • Zod schema defining input parameters for element locator tools, used by browser_find_element.
    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'), };
  • Core helper method in ElementService that creates a locator using LocatorFactory and waits for the element using Selenium's 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); }
  • Top-level tool registration function that calls registerElementTools, thereby registering the browser_find_element tool.
    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