Skip to main content
Glama

click

Simulate mouse clicks on web page elements using CSS selectors to automate browser interactions for testing or automation workflows.

Instructions

Click an element on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the element
buttonNoMouse button to clickleft
clickCountNoNumber of clicks
delayNoDelay between mousedown and mouseup in ms
timeoutNoTimeout in milliseconds
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • Handler for the 'click' tool: registers the tool, waits for the element selector to be visible, performs the click with options (button, count, delay), and returns success or handles errors appropriately.
    server.tool( 'click', 'Click an element on the page', clickSchema.shape, async ({ selector, button, clickCount, delay, timeout, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; const timeoutMs = timeout ?? getDefaultTimeout(); try { // Wait for element to be visible const element = await page.waitForSelector(selector, { timeout: timeoutMs, visible: true, }); if (!element) { return handleResult(err(selectorNotFound(selector))); } await element.click({ button: (button ?? 'left') as MouseButton, clickCount: clickCount ?? 1, delay: delay, }); return handleResult(ok({ clicked: true, selector })); } catch (error) { if (error instanceof Error && error.message.includes('waiting for selector')) { return handleResult(err(selectorNotFound(selector))); } return handleResult(err(normalizeError(error))); } } );
  • Zod schema defining the input parameters for the click tool: selector (required), button (default 'left'), clickCount (1-3, default 1), delay (0-5000ms), timeout, tabId (optional).
    export const clickSchema = z.object({ selector: selectorSchema, button: z.enum(['left', 'right', 'middle']).optional().default('left').describe('Mouse button to click'), clickCount: z.number().int().min(1).max(3).optional().default(1).describe('Number of clicks'), delay: z.number().int().min(0).max(5000).optional().describe('Delay between mousedown and mouseup in ms'), timeout: timeoutSchema, tabId: tabIdSchema, });
  • src/server.ts:24-24 (registration)
    High-level registration call that invokes registerInteractionTools, which includes the click tool registration.
    registerInteractionTools(server);

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/andytango/puppeteer-mcp'

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