click
Automate web interactions by clicking elements using CSS selectors for browser automation tasks like testing and data extraction.
Instructions
Click an element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes |
Implementation Reference
- src/controllers/playwright.ts:115-135 (handler)The core handler function implementing the click tool logic using Playwright's page.click for the given selector.async click(selector?: string): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } if (selector) { this.log('Clicking element', selector); await this.state.page.click(selector); } else { this.log('Clicking at position', this.currentMousePosition); await this.state.page.mouse.click(this.currentMousePosition.x, this.currentMousePosition.y); } this.log('Click complete'); } catch (error: any) { console.error('Click error:', error); throw new BrowserError( 'Failed to click', selector ? 'Check if the element exists and is visible' : 'Check if mouse position is valid' ); } }
- src/server.ts:44-54 (schema)Schema definition for the 'click' tool, specifying name, description, and required 'selector' input.const CLICK_TOOL: Tool = { name: "click", description: "Click an element", inputSchema: { type: "object", properties: { selector: { type: "string" } }, required: ["selector"] } };
- src/server.ts:612-623 (handler)MCP callTool handler case for 'click' that validates the selector argument and invokes the Playwright controller.case 'click': { if (!args.selector) { return { content: [{ type: "text", text: "Selector is required" }], isError: true }; } await playwrightController.click(args.selector as string); return { content: [{ type: "text", text: "Click successful" }] }; }
- src/server.ts:555-565 (registration)Server initialization that registers the tools object (including 'click' tool) in MCP capabilities.const server = new Server( { name: "playmcp-browser", version: "1.0.0", }, { capabilities: { tools, }, } );
- src/server.ts:518-518 (registration)Specific registration of the 'click' tool in the tools dictionary used for MCP server capabilities.click: CLICK_TOOL,