browser_file_upload
Upload files to web forms by locating file input elements and providing the file path for automated browser testing and form submissions.
Instructions
Uploads a file using a file input element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| filePath | Yes | Absolute path to the file to upload | |
| timeout | No | Maximum time to wait for element in milliseconds | |
| value | Yes | Value for the locator strategy |
Implementation Reference
- src/tools/elementTools.ts:359-385 (registration)Registers the 'browser_file_upload' tool on the MCP server. Includes schema definition and the handler function that locates the file input element and delegates upload to ElementService.server.tool( 'browser_file_upload', 'Uploads a file using a file input element', { ...locatorSchema, filePath: z.string().describe('Absolute path to the file to upload'), }, async ({ by, value, filePath, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); await elementService.uploadFile({ by, value, filePath, timeout }); return { content: [{ type: 'text', text: 'File upload initiated' }], }; } catch (e) { return { content: [ { type: 'text', text: `Error uploading file: ${(e as Error).message}`, }, ], }; } } );
- src/services/elementService.ts:45-48 (helper)Implements the file upload logic by finding the file input element using the locator and sending the absolute file path via Selenium's sendKeys method, which handles file upload in browsers.async uploadFile(params: LocatorParams & { filePath: string }): Promise<void> { const element = await this.findElement(params); await element.sendKeys(params.filePath); }
- src/types/index.ts:29-35 (schema)Base schema for element locators (by, value, timeout), spread into the tool's input schema.export const locatorSchema = { by: z .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink']) .describe('Locator strategy to find element'), value: z.string().describe('Value for the locator strategy'), timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'), };
- src/tools/index.ts:10-10 (registration)Calls registerElementTools as part of registering all tools, which includes browser_file_upload.registerElementTools(server, stateManager);