Skip to main content
Glama

browser_click

Simulate mouse clicks on web page elements using CSS selectors for automated browser interaction and testing.

Instructions

Click on an element specified by selector

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes

Implementation Reference

  • The handler function that implements the core logic of the browser_click tool. It validates the selector input using Zod, ensures the Playwright browser is connected, retrieves the current page, executes page.click(selector), and returns a success message or error response in MCP format.
    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:155-190 (registration)
    The registration of the 'browser_click' tool in the MCP server using registerTool, including tool metadata (title, description), inline input schema, and the handler function.
    this.server.registerTool( '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 parameters (selector: string). Matches the inline schema used in registration.
    export const BrowserClickInputSchema = z.object({ selector: z.string() });
  • Helper method in PlaywrightManager called by the handler to ensure the browser connection is active before performing the click operation.
    async ensureConnected(): Promise<void> { const connected = await this.isConnected(); if (!connected) { await this.cleanup(); await this.connect(); } }
  • Helper method in PlaywrightManager to retrieve the current Playwright Page instance used for executing page.click().
    getPage(): Page { if (!this.page) { throw new Error('Playwright not connected. Call connect() first.'); } return this.page; }

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