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
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| value | Yes | Value for the locator strategy | |
| timeout | No | Maximum time to wait for element in milliseconds |
Implementation Reference
- src/tools/elementTools.ts:66-85 (handler)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}`, }, ], }; } } );
- src/tools/elementTools.ts:62-86 (registration)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}`, }, ], }; } } );
- src/types/index.ts:29-35 (schema)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'), };
- src/services/elementService.ts:24-27 (helper)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(); }
- src/tools/index.ts:10-10 (registration)Invocation of registerElementTools which includes browser_click registration.registerElementTools(server, stateManager);