fill_by_uid
Fill text inputs and textareas using element UIDs for browser automation testing and web scraping. Works with Firefox DevTools MCP server to populate form fields programmatically.
Instructions
Fill a text input or textarea identified by its UID. Keep values short and safe. TIP: Take a fresh snapshot if the UID becomes stale.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | The UID of the input element | |
| value | Yes | The text value to fill into the input |
Implementation Reference
- src/tools/input.ts:193-217 (handler)MCP tool handler for fill_by_uid: validates input, retrieves Firefox instance, calls underlying fillByUid method, handles errors with UID-specific messaging.export async function handleFillByUid(args: unknown): Promise<McpToolResponse> { try { const { uid, value } = args as { uid: string; value: string }; if (!uid || typeof uid !== 'string') { throw new Error('uid parameter is required and must be a string'); } if (value === undefined || typeof value !== 'string') { throw new Error('value parameter is required and must be a string'); } const { getFirefox } = await import('../index.js'); const firefox = await getFirefox(); try { await firefox.fillByUid(uid, value); return successResponse(`✅ fill ${uid}`); } catch (error) { throw handleUidError(error as Error, uid); } } catch (error) { return errorResponse(error as Error); } }
- src/tools/input.ts:62-79 (schema)Input schema and metadata for the fill_by_uid tool, defining uid (string, required) and value (string, required) parameters.export const fillByUidTool = { name: 'fill_by_uid', description: 'Fill text input/textarea by UID.', inputSchema: { type: 'object', properties: { uid: { type: 'string', description: 'Input element UID from snapshot', }, value: { type: 'string', description: 'Text to fill', }, }, required: ['uid', 'value'], }, };
- src/index.ts:103-147 (registration)Registration of fill_by_uid handler in the central toolHandlers Map used by the MCP server.const toolHandlers = new Map< string, (input: unknown) => Promise<{ content: Array<{ type: string; text: string }>; isError?: boolean }> >([ // Pages ['list_pages', tools.handleListPages], ['new_page', tools.handleNewPage], ['navigate_page', tools.handleNavigatePage], ['select_page', tools.handleSelectPage], ['close_page', tools.handleClosePage], // Script evaluation - DISABLED (see docs/future-features.md) // ['evaluate_script', tools.handleEvaluateScript], // Console ['list_console_messages', tools.handleListConsoleMessages], ['clear_console_messages', tools.handleClearConsoleMessages], // Network ['list_network_requests', tools.handleListNetworkRequests], ['get_network_request', tools.handleGetNetworkRequest], // Snapshot ['take_snapshot', tools.handleTakeSnapshot], ['resolve_uid_to_selector', tools.handleResolveUidToSelector], ['clear_snapshot', tools.handleClearSnapshot], // 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:150-191 (registration)Registration of fillByUidTool schema in the allTools array returned by listTools.const allTools = [ // Pages tools.listPagesTool, tools.newPageTool, tools.navigatePageTool, tools.selectPageTool, tools.closePageTool, // Script evaluation - DISABLED (see docs/future-features.md) // tools.evaluateScriptTool, // Console tools.listConsoleMessagesTool, tools.clearConsoleMessagesTool, // Network tools.listNetworkRequestsTool, tools.getNetworkRequestTool, // Snapshot tools.takeSnapshotTool, tools.resolveUidToSelectorTool, tools.clearSnapshotTool, // Input tools.clickByUidTool, tools.hoverByUidTool, tools.fillByUidTool, tools.dragByUidToUidTool, tools.fillFormByUidTool, tools.uploadFileByUidTool, // Screenshot tools.screenshotPageTool, tools.screenshotByUidTool, // Utilities tools.acceptDialogTool, tools.dismissDialogTool, tools.navigateHistoryTool, tools.setViewportSizeTool, ];
- src/firefox/dom.ts:166-183 (helper)Core implementation of fillByUid: resolves UID to WebElement, clears the input field, sends the new value using Selenium WebDriver, and waits for events.async fillByUid(uid: string, value: string): Promise<void> { if (!this.resolveUid) { throw new Error('fillByUid: resolveUid callback not set. Ensure snapshot is initialized.'); } const el = await this.resolveUid(uid); try { await el.clear(); } catch { // Some inputs may not support clear(); fall back to select-all + delete await el.sendKeys(Key.chord(Key.CONTROL, 'a'), Key.DELETE); } await el.sendKeys(value); // Wait for events to propagate await this.waitForEventsAfterAction(); }