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.
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.
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.
Here is an example that works in my specific case for uploading multiple photos, may help someone out...
Photos is an array of strings i.e. ['/Users/foo/bar/beautiful_forest-1546653.jpg', '/Users/foo/bar/DTHalloween.jpg'] then I loop through and upload them by send_keys. I ensure they are uploaded by checking to see if the uploaded filename exists in the DOM, which it will if successfull (specific to my case). FWIW, I'm testing a react.js web app btw.
def uploadPhoto(self, photos):
try:
drop_zone = self.driver.find_element_by_id('photo-file-input')
alreadyUploaded = [] # keep track of uploaded files
for photo in photos:
photo_name = photo.split('/')[-1].split('.')[0]
if photo_name.lower() in alreadyUploaded:
print("Photo already uploaded with name: ( "+ photo_name.lower()+" )")
continue
alreadyUploaded.append(photo_name.lower())
drop_zone.send_keys(photo)
try:
WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.XPATH, '//img[contains(@data-galleryid, '+ photo_name +')]'))
)
except Exception, e:
raise Exception(e)
return True
except Exception, e:
print 'Failed to upload photo {}'.format(str(e))
return False
Try using this because for me works :
@staticmethod
def set_multiple_file_file():
element = (INSERT_FILE)
ROOT_DIR = your.path
first_path = archive1.something
second_path = archive2.something
third_path = archive3.something
element.send_keys(ROOT_DIR + first_path + ROOT_DIR + second_path + ROOT_DIR + third_path)