Skip to main content
Glama

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

NameRequiredDescriptionDefault
selectorYes

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "selector": { "type": "string" } }, "required": [ "selector" ], "type": "object" }

Implementation Reference

  • 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 }; } }
  • Zod input schema definition for the browser_click tool, defining the expected 'selector' parameter.
    export const BrowserClickInputSchema = z.object({ selector: z.string() });
  • TypeScript type inferred from BrowserClickInputSchema for type safety.
    export type BrowserClickInput = z.infer<typeof BrowserClickInputSchema>;

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/b3nw/playwright-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server