Skip to main content
Glama

browser_click

Click web elements using Selenium WebDriver by specifying locator strategies like ID, CSS, or XPath for browser automation and testing.

Instructions

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

  • MCP tool handler for browser_click: instantiates ElementService and calls clickElement on the located element.
      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}`,
              },
            ],
          };
        }
      }
    );
  • Registration of the browser_click tool using server.tool in registerElementTools function.
    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}`,
              },
            ],
          };
        }
      }
    );
  • locatorSchema defining the input parameters (by, value, timeout) for element location in browser_click.
    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 implementation of element click using Selenium WebDriver's element.click() after locating the element.
    async clickElement(params: LocatorParams): Promise<void> {
      const element = await this.findElement(params);
      await element.click();
    }
  • Invocation of registerElementTools which includes browser_click registration.
    registerElementTools(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