browser_click
Simulate user clicks on web elements using specified selectors to automate interactions directly within a Playwright MCP Server environment for streamlined web automation tasks.
Instructions
Click on an element specified by selector
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"selector": {
"type": "string"
}
},
"required": [
"selector"
],
"type": "object"
}
Implementation Reference
- src/server.ts:164-188 (handler)Handler function that validates input, ensures Playwright connection, clicks the element using page.click(), and returns success or error response.async (params: any) => { try { const input = z.object({ selector: z.string() }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); await page.click(input.selector); return { content: [{ type: 'text', text: `Successfully clicked element: ${input.selector}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Click failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; }
- src/server.ts:156-189 (registration)Registers the 'browser_click' tool with MCP server, including title, description, inline input schema, and handler function.'browser_click', { title: 'Click Element', description: 'Click on an element specified by selector', inputSchema: { selector: z.string() } }, async (params: any) => { try { const input = z.object({ selector: z.string() }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); await page.click(input.selector); return { content: [{ type: 'text', text: `Successfully clicked element: ${input.selector}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Click failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/types.ts:27-29 (schema)Zod input schema definition for the browser_click tool, defining the expected 'selector' parameter.export const BrowserClickInputSchema = z.object({ selector: z.string() });
- src/types.ts:62-62 (schema)TypeScript type inferred from BrowserClickInputSchema for type safety.export type BrowserClickInput = z.infer<typeof BrowserClickInputSchema>;