Puppeteer: Multiple file uploads only work with <input type=file multiple>
Several files are uploaded to a file input without the multiple attribute.
Several files are uploaded to a file input without the multiple attribute.
Error message
Multiple file uploads only work with <input type=file multiple>
How this error happens
A native file input accepts multiple files only when it has the multiple attribute.
The snippets use an open Puppeteer page named page.
await page.setContent(
'<input id="upload" type="file">'
);
const input = await page.$("#upload");
await input.uploadFile(
"/absolute/path/first.csv",
"/absolute/path/second.csv"
);
How to fix
Upload one file to a single-file input. If you own the form and it is meant to accept several files, give it the multiple attribute.
const input = await page.$("#upload");
await input.uploadFile(
"/absolute/path/first.csv"
);
Things to keep in mind
The paths must refer to existing local files. Do not add multiple to a third-party form if the server only accepts one file.