Skip to main content

setFiles

Set the files of an <input type="file"> with the WebDriver BiDi input.setFiles command.

The paths are opened by the browser. They are not copied and not uploaded. A relative path is resolved against process.cwd(), so a path the test process can open is the path a local browser opens. A remote browser needs a path on the machine that runs the browser.

This command needs a BiDi session. On a classic session, setValue still types a path the local browser can already see.

Passing more than one path to an input without multiple, a disabled input, or an element that is not a file input fails with the BiDi error unable to set file input.

Usage​

await $(selector).setFiles(files)

Parameters​

NameTypeDetails
filesstring, string[]path or paths the browser machine can read

Example​

setFiles.js
it('sets a file input', async () => {
await $('#file-upload').setFiles('/path/to/file.png')
await $('#file-upload').setFiles(['/path/to/a.png', '/path/to/b.png'])
});

Welcome! How can I help?

WebdriverIO AI Copilot