Skip to main content
Glama

click

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

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

  • Zod input schema for the click tool defining parameters: selector (required), button (default 'left'), clickCount (1-3, default 1), delay (0-5000ms), timeout, tabId.
    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, });
  • Registration of the click tool using server.tool with name 'click', description, and clickSchema.shape as input schema.
    server.tool( 'click', 'Click an element on the page', clickSchema.shape,
  • The handler function for the click tool: retrieves the page for the tab, waits for the selector to be visible, clicks the element with specified button, count, and delay, handles errors including selector not found.
    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))); } }

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