click
Click elements on web pages using CSS selectors for browser automation and testing workflows with Chromium on ARM64 devices.
Instructions
Click an element on the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element to click |
Implementation Reference
- index.js:637-675 (handler)The core handler function for the 'click' tool. It uses Chrome DevTools Protocol (CDP) to locate the element by CSS selector, calculates its center point from the box model, and dispatches mouse press/release events to simulate a click.async click(selector) { await this.ensureChromium(); // Find element const doc = await this.sendCDPCommand('DOM.getDocument'); const element = await this.sendCDPCommand('DOM.querySelector', { nodeId: doc.root.nodeId, selector }); if (!element.nodeId) { throw new Error(`Element not found: ${selector}`); } // Get element box const box = await this.sendCDPCommand('DOM.getBoxModel', { nodeId: element.nodeId }); const quad = box.model.content; const x = (quad[0] + quad[4]) / 2; const y = (quad[1] + quad[5]) / 2; // Click await this.sendCDPCommand('Input.dispatchMouseEvent', { type: 'mousePressed', x, y, button: 'left', clickCount: 1 }); await this.sendCDPCommand('Input.dispatchMouseEvent', { type: 'mouseReleased', x, y, button: 'left', clickCount: 1 }); return { content: [{ type: 'text', text: `Clicked element: ${selector}` }], }; }
- index.js:138-151 (schema)The input schema definition for the 'click' tool, specifying that it requires a 'selector' string parameter.{ name: 'click', description: 'Click an element on the page', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element to click', }, }, required: ['selector'], }, },
- index.js:355-356 (registration)Registration of the 'click' tool handler in the MCP CallToolRequest switch statement, dispatching calls to the click implementation.case 'click': return await this.click(args.selector);