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
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the element | |
| button | No | Mouse button to click | left |
| clickCount | No | Number of clicks | |
| delay | No | Delay between mousedown and mouseup in ms | |
| timeout | No | Timeout in milliseconds | |
| tabId | No | Tab ID to operate on (uses active tab if not specified) |
Implementation Reference
- src/tools/interaction.ts:19-57 (handler)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))); } } );
- src/schemas.ts:51-58 (schema)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);