Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload multiple files using Python Selenium WebDriver

I have a html element

<input type=file multiple="">

How can I use send_keys to upload multiple files?

Currently this works with uploading single file. I want to use this to upload multiple files

I tried Comma separated paths but no luck.

like image 510
user3587178 Avatar asked Nov 02 '25 15:11

user3587178


2 Answers

path = “/home/downloads/” send_keys(path + “file1.csv \n” + path + “file2.csv”)

I found it working in my code. Do try this and give me update on the error you got.

like image 178
Prerna Gaikwad Avatar answered Nov 04 '25 07:11

Prerna Gaikwad


First, send all files to the element and then submit.

Following is Ruby code, but you can apply same logic for Python:

uploader = driver.find_element(id: 'file-upload')
uploader.send_keys 'path_to_file1'
uploader.send_keys 'path_to_file2'
uploader.send_keys 'path_to_file3'
.
.
.
uploader.submit

I'm not sure if this will work, but just give a try and let me know the result.

like image 44
Alpha Avatar answered Nov 04 '25 06:11

Alpha