[Firefox]upload multiple files at one time

Hello everyone,

I’m struggling with an issue and maybe you will be able to help me. i searched first if there was a similar topic, there were some but not really helpful for my case.
I’m trying to upload multiple files at once with Robotframework and Firefox but i’m facing an error that i don’t understand until now:

/Users/xxx/file1.jpg
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5
InvalidArgumentError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:384:5
interaction.uploadFiles@chrome://remote/content/marionette/interaction.sys.mjs:579:13

I’m using this:
Choose File locator ${file_paths}
where ${file_paths}=/Users/xxx/file1.jpg \n /Users/xxx/file2.jpg
This is working on Chrome but not on Firefox.

If anyone can help me, i would appreciate. Thank you

Hi,

It seems Firefox doesn’t support the multiple file upload with the \n separator as in Chrome.

Did you tried something like this:

VAR    ${FILES}    /Users/xxx/file1.jpg    /Users/xxx/file2.jpg
FOR    ${file}    IN    @{FILES}
    Choose File    locator    ${file}
END

Regards
Charlie

hello Charlie,
I did not test this because i think that by doing a loop the files will be uploaded one by one and it is not the case i would like to test.
But it doesn’t hurt to check .

I tested the solution proposed by Charlie. the files are sent one by one not at once

Damn…
Tbh I don’t use Firefox, but only Chrome with Choose File.

I see in the Library that it’s “just” send key:

self.find_element(locator).send_keys(file_path)

Maybe the separator has to be something else:

  • \n (escaped)
  • a comma…

Regards
Charlie

Code for Choose File is essentially locate the selector and write the string with selenium’s send_keys() method. This line: SeleniumLibrary/src/SeleniumLibrary/keywords/formelement.py at 68b81495dc64fda6f5fa7a7359f199581404fd61 · robotframework/SeleniumLibrary · GitHub

With this “knowledge” - its up to the browser to decide what it would do with the “keys pressed by the user”. And if you send press following characters:

/Users/xxx/file1.jpg \n /Users/xxx/file2.jpg

its up to the browser to decide how it will interpret that.

It might very well be that

  1. Firefox expects the filenames to be written without spaces. Your input string will send one space after the initial filename and one space before the second. Chrome might be doing handle this and maybe firefox dont ?
  2. Maybe firefox does not support this ? Have you tried to attach 2 files manually and see how the files are sent ? And this is what @CharlieScene mentioned too. If this is the case, I’d start looking for possible workaround with javascript or reformat your input string.

Also worth mentioning is that behaviour of how file sends happen depends on the actual SUT but giving more information without knowing how its implemented, hard to say.

I’m starting to think like Charlie that Firefox does not support the multiple files upload.
I’m working in Q&A, i don’t know how to develop something in javascript to help doing this action.
I will try other separators but if nothing works i will just upload files one by one

Thanks both for your help

@Mia

I think I found the solution.
Installed Firefox (v134.0.2) and check why it didn’t worked.

On Chrome, this works well:

VAR   ${files}   C:/Users/Downloads/myfile1.txt\nC:/Users/Downloads/myfile2.txt    
Choose File    //input[@type='file']    ${files}

On Firefox this already doesn’t work, saying the path doesn’t exist:

VAR   ${files}   C:/Users/Downloads/myfile1.txt   
Choose File    //input[@type='file']    ${files}

Stacktrace is as follow :

[ FAIL ] InvalidArgumentException: Message: File not found: C:$Users$Downloadsmyfile1.txt
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5
InvalidArgumentError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:384:5
interaction.uploadFiles@chrome://remote/content/marionette/interaction.sys.mjs:579:13

After tryring to escape etc… this works on Firefox (replace forward slashes by : ${/} ).
I assume it doesn’t manage the slashes as in Chrome:

VAR    ${files}    C:${/}Users${/}Downloads${/}myfile1.txt\nC:${/}Users${/}Downloads${/}myfile2.txt
Choose File    //input[@type='file']    ${files}

And by the way this works also if you need to pass a list:

VAR    @{files}    C:${/}Users${/}Downloads${/}myfile1.txt     C:${/}Users${/}Downloads${/}myfile1.txt
FOR   ${file}   IN   @{files}
    Choose File    //input[@type='file']    ${file}
END

Hope this helps :slightly_smiling_face:

Charlie

1 Like

Nice Charlie, I’m going to ty this solution immediately.
Thank you :slight_smile:

It worked :slight_smile:
Thank you again @CharlieScene

1 Like

Looks like the difference is the whitespace in the string unless @Mia was actually on windows

FYI i’m working on macos

Yeah, thats why using ${/} wont do any difference as macos uses /, ${/} on windows will correctly turn into \. What @CharlieScene actual code has a difference is that fact that

a) If using a list or b) not having space bar before and after that \n is what fixed the issue which i tried to convey with

Your input string will send one space after the initial filename and one space before the second.

1 Like