'How to upload multiple files using webdriverIO?
I'm able to upload a single using Webdriverio. But there are no options to upload multiple files from a single folder. Also I did tried searching for help on internet. There seems to be no discussions or topics to help. Please suggest how to upload multiple files from single folder using WebdriverIo. Thanks!
Solution 1:[1]
The question here is: how multiple files are stored into input file tag in a HTML page?
HTML example:
<input type="file" id="test-file" name="input-file" multiple>
This function should be useful for single or multiple file, even for hidden or not displayed input:
const uploadFiles = async (filesPath, selector) => {
const files = Array.isArray(filesPath) ? filesPath : [filesPath];
const el = await $(selector);
await browser.execute((el) => el.style.display = 'block', el);
await el.waitForDisplayed();
await el.addValue(files.join('\n'));
}
await uploadFiles(['Users/username/etc.jpg', 'Users/username/etc.jpg'], '#test-file')
That's it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 70X |
