click_by_uid
Click or double-click browser elements using unique identifiers for automated testing, web scraping, and browser control tasks.
Instructions
Click an element identified by its UID. Supports double-click via dblClick=true. TIP: Take a fresh snapshot if the UID becomes stale.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dblClick | No | If true, performs a double-click (default: false) | |
| uid | Yes | The UID of the element to click |
Implementation Reference
- src/tools/input.ts:28-45 (schema)Tool schema defining the 'click_by_uid' tool with input parameters: uid (string, required), dblClick (boolean, optional)export const clickByUidTool = { name: 'click_by_uid', description: 'Click element by UID. Set dblClick for double-click.', inputSchema: { type: 'object', properties: { uid: { type: 'string', description: 'Element UID from snapshot', }, dblClick: { type: 'boolean', description: 'Double-click (default: false)', }, }, required: ['uid'], }, };
- src/tools/input.ts:149-169 (handler)Handler function that parses arguments, validates uid, initializes Firefox if needed, executes clickByUid, and returns success/error MCP responseexport async function handleClickByUid(args: unknown): Promise<McpToolResponse> { try { const { uid, dblClick } = args as { uid: string; dblClick?: boolean }; if (!uid || typeof uid !== 'string') { throw new Error('uid parameter is required and must be a string'); } const { getFirefox } = await import('../index.js'); const firefox = await getFirefox(); try { await firefox.clickByUid(uid, dblClick); return successResponse(`✅ ${dblClick ? 'dblclick' : 'click'} ${uid}`); } catch (error) { throw handleUidError(error as Error, uid); } } catch (error) { return errorResponse(error as Error); } }
- src/index.ts:130-147 (registration)Registration of click_by_uid handler in the main toolHandlers Map used by the MCP server// Input ['click_by_uid', tools.handleClickByUid], ['hover_by_uid', tools.handleHoverByUid], ['fill_by_uid', tools.handleFillByUid], ['drag_by_uid_to_uid', tools.handleDragByUidToUid], ['fill_form_by_uid', tools.handleFillFormByUid], ['upload_file_by_uid', tools.handleUploadFileByUid], // Screenshot ['screenshot_page', tools.handleScreenshotPage], ['screenshot_by_uid', tools.handleScreenshotByUid], // Utilities ['accept_dialog', tools.handleAcceptDialog], ['dismiss_dialog', tools.handleDismissDialog], ['navigate_history', tools.handleNavigateHistory], ['set_viewport_size', tools.handleSetViewportSize], ]);
- src/index.ts:174-180 (registration)Inclusion of clickByUidTool in the allTools array returned by listTools MCP request// Input tools.clickByUidTool, tools.hoverByUidTool, tools.fillByUidTool, tools.dragByUidToUidTool, tools.fillFormByUidTool, tools.uploadFileByUidTool,
- src/firefox/dom.ts:132-147 (helper)Core implementation: resolves UID to WebElement, ensures visibility, performs click or doubleClick using Selenium actions, waits for eventsasync clickByUid(uid: string, dblClick = false): Promise<void> { if (!this.resolveUid) { throw new Error('clickByUid: resolveUid callback not set. Ensure snapshot is initialized.'); } const el = await this.resolveUid(uid); await this.driver.wait(until.elementIsVisible(el), 5000).catch(() => {}); if (dblClick) { await this.driver.actions({ async: true }).doubleClick(el).perform(); } else { await el.click(); } // Wait for events to propagate await this.waitForEventsAfterAction(); }