3

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.

1
  • Are you sure? If input field doesn't have boolean @multiple then it probably doesn't support uploading multiple files at the time Commented Feb 5, 2021 at 16:04

2 Answers 2

6

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:

Sign up to request clarification or add additional context in comments.

1 Comment

Hii, this is not working for some reason, I even tried like this selenium.common.exceptions.InvalidArgumentException: Message: File not found: file:///C:/Users/amel.islamovic_bbm/Desktop/projects/twitter-bot/results/haber/1711027971111124992.png \n file:///C:/Users/amel.islamovic_bbm/Desktop/projects/twitter-bot/results/haber/1711027975989207040.png, any help?
0

@undetected-selenium answer works for me but i used join() function instead of string concatenation to solve the File not found exception.

file_paths = [] #array of file paths
combined_paths = "\n".join(file_paths)
driver.FindElementById("upload1").send_keys(combined_paths)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.