click_element
Automate web element interactions by clicking on specific elements using CSS selectors with the MCP Browser Server, streamlining browser automation tasks.
Instructions
Click on an element by CSS selector
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element to click | |
| timeout | No | Timeout in milliseconds |
Implementation Reference
- src/index.ts:483-499 (handler)The main handler function for the click_element tool within the CallToolRequestSchema switch statement. Validates input parameters using ClickElementSchema, performs the click action using Playwright's currentPage.click method, and returns a success confirmation message.case 'click_element': { if (!currentPage) { throw new Error('No browser page available. Launch a browser first.'); } const params = ClickElementSchema.parse(args); await currentPage.click(params.selector, { timeout: params.timeout }); return { content: [ { type: 'text', text: `Clicked element: ${params.selector}` } ] }; }
- src/index.ts:28-31 (schema)Zod schema defining the input validation for the click_element tool: requires a 'selector' string (CSS selector) and optional 'timeout' number (default 5000ms). Used for parsing arguments in the handler.const ClickElementSchema = z.object({ selector: z.string(), timeout: z.number().default(5000) });
- src/index.ts:177-195 (registration)Registration of the click_element tool in the ListToolsRequestSchema handler's tools array response. Specifies the tool name, description, and JSON inputSchema matching the Zod schema.{ name: 'click_element', description: 'Click on an element by CSS selector', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element to click' }, timeout: { type: 'number', default: 5000, description: 'Timeout in milliseconds' } }, required: ['selector'] } },