pdfs =[file1, file2, file3]
uploadButton = browser.find_element_by_xpath("//input[@type='file']")
for i in range(len(pdfs)):
uploadButton.send_keys(pdfs[i])
The above code I am using for uploading multiple files using send_keys() in ChromeDriver. Here it will work fine in the 1st iteration in the 2nd iteration it will upload 2 files and in 3rd iteration uploads 3 files. In every iteration duplicate files are uploading. I need a solution to upload one by one file using for loop without duplication. I know we can upload all files at one time like this
files = file1 '\n' file2 '\n' file3
uploadButton.send_keys(files)
But I don't wants to upload all files at once I have to upload one by one in using for loop. Can anyone help me out of this problem using Python Selenium.
CodePudding user response:
If your input doesn't allow multiple files, then this is not possible. You would have to select file1, upload and then go back to the page and repeat the process for each file.
CodePudding user response:
Have you tried declaring your webelement within each iteration?
Like this?
pdfs =[file1, file2, file3]
for i in range(len(pdfs)):
uploadButton = browser.find_element_by_xpath("//input[@type='file']")
uploadButton.send_keys(pdfs[i])