pilot_file_upload
Upload files to web forms by specifying file paths and targeting file input elements using references or CSS selectors.
Instructions
Upload file(s) to a file input element.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ref | Yes | File input element ref or CSS selector | |
| paths | Yes | File paths to upload |
Implementation Reference
- src/tools/interaction.ts:280-311 (handler)Implementation of the pilot_file_upload tool, including schema definition and execution logic.
server.tool( 'pilot_file_upload', 'Upload file(s) to a file input element.', { ref: z.string().describe('File input element ref or CSS selector'), paths: z.array(z.string()).describe('File paths to upload'), }, async ({ ref, paths }) => { await bm.ensureBrowser(); try { for (const fp of paths) { if (!fs.existsSync(fp)) throw new Error(`File not found: ${fp}`); } const page = bm.getPage(); const resolved = await bm.resolveRef(ref); if ('locator' in resolved) { await resolved.locator.setInputFiles(paths); } else { await page.locator(resolved.selector).setInputFiles(paths); } const fileInfo = paths.map(fp => { const stat = fs.statSync(fp); return `${path.basename(fp)} (${stat.size}B)`; }).join(', '); bm.resetFailures(); return { content: [{ type: 'text' as const, text: `Uploaded: ${fileInfo}` }] }; } catch (err) { bm.incrementFailures(); return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } );