Skip to main content
Glama

browser_file_upload

Upload files to web forms by specifying file paths and element locators for automated browser testing and interaction.

Instructions

Uploads a file using a file input element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesLocator strategy to find element
valueYesValue for the locator strategy
timeoutNoMaximum time to wait for element in milliseconds
filePathYesAbsolute path to the file to upload

Implementation Reference

  • Registers the browser_file_upload MCP tool, defining its input schema (locator strategy, value, timeout, filePath) and handler function that uses ElementService to perform the upload.
    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}`, }, ], }; } } );
  • Core implementation of file upload in ElementService: locates the file input element and sends the absolute file path using Selenium's sendKeys method.
    async uploadFile(params: LocatorParams & { filePath: string }): Promise<void> { const element = await this.findElement(params); await element.sendKeys(params.filePath); }
  • locatorSchema defining the input parameters for element location (by, value, timeout), spread into the tool's 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'), };

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/pshivapr/selenium-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server