Skip to main content
Glama

browser_click

Click on web page elements using various locator strategies like ID, CSS, or XPath to automate browser interactions and testing workflows.

Instructions

Perform a click on 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

  • Registers the 'browser_click' tool with server.tool(), providing schema from locatorSchema and a handler that instantiates ElementService and calls clickElement.
    server.tool( 'browser_click', 'Perform a click on an element', { ...locatorSchema }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); await elementService.clickElement({ by, value, timeout }); return { content: [{ type: 'text', text: 'Element clicked' }], }; } catch (e) { return { content: [ { type: 'text', text: `Error clicking element: ${(e as Error).message}`, }, ], }; } } );
  • Implements the core logic for clicking an element: finds the element using locator and calls Selenium's click() method.
    async clickElement(params: LocatorParams): Promise<void> { const element = await this.findElement(params); await element.click(); }
  • Zod schema for locator parameters (by, value, timeout), spread into the browser_click tool input 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'), };
  • Helper method used by clickElement to locate the WebElement using LocatorFactory and wait for it.
    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 registration function that calls registerElementTools (which registers browser_click).
    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