playwright_upload_file
Upload files to web page file input elements using CSS selectors and local file paths for browser automation tasks.
Instructions
Upload a file to an input[type='file'] element on the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | CSS selector for the file input element | |
| filePath | Yes | Absolute path to the file to upload |
Implementation Reference
- src/tools.ts:184-195 (schema)Defines the tool name, description, and input schema for 'playwright_upload_file'.{ name: "playwright_upload_file", description: "Upload a file to an input[type='file'] element on the page", inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector for the file input element" }, filePath: { type: "string", description: "Absolute path to the file to upload" } }, required: ["selector", "filePath"], }, },
- src/tools/browser/interaction.ts:139-150 (handler)The UploadFileTool class implements the core logic for uploading a file using Playwright's setInputFiles method on the specified selector.export class UploadFileTool extends BrowserToolBase { /** * Execute the upload file tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { await page.waitForSelector(args.selector); await page.setInputFiles(args.selector, args.filePath); return createSuccessResponse(`Uploaded file '${args.filePath}' to '${args.selector}'`); }); } }
- src/toolHandler.ts:502-503 (registration)Dispatches the tool call to the UploadFileTool's execute method in the main tool handler switch statement.case "playwright_upload_file": return await uploadFileTool.execute(args, context);
- src/toolHandler.ts:327-327 (registration)Instantiates the UploadFileTool instance during tool initialization.if (!uploadFileTool) uploadFileTool = new UploadFileTool(server);
- src/tools.ts:459-459 (registration)Lists 'playwright_upload_file' in the BROWSER_TOOLS array for conditional browser launching."playwright_upload_file",