简体   繁体   中英

How to upload multiple files using SendKeys Selenium

I have an element with following HTML:

<input type="file" name="upload" value="[]" id="upload1" class="upload">

To the best of my understanding its value is an array/list and it's supposed to store uploaded files paths (multiple files are allowed).

I use following code to upload ONE file:

.FindElementById("upload1").SendKeys ("C:\file1.txt") 

and it works just fine. However, i need to upload multiple files but I do not get how to populate the array with multiple filepaths using SendKeys .

I use vba to automated data entry from within excel.

To upload multiple files you can construct the character string adding all the absolute path of the files seperated by \n as follows:

.FindElementById("upload1").SendKeys("C:/TextFile1.txt \n C:/TextFile2.txt \n C:/TextFile3.txt");

References

You can find a couple of relevant detailed discussions in:

EDIT

Web page interface is as follows.

A user sees "Browse" button and "Add More" button.

"Add More" button and its script: button type="button" class="button md-btn md-btn-wave waves-effect waves-button md-btn-primary" id="addFile">Add More

When "Add More" is clicked second "Browse" button appears. Second "Browse" button script: input type="file" name="upload" class="upload">

A user can add up to 3 more "Browse" buttons (4 in total). The script of the 3 added is the same (input type="file" name="upload" class="upload">).

Any ideas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM