Reputation: 43
I'm wondering is it possible, with some parameters to use Choose File keyword to Choose a folder instead of a single file?
The HTML for the file upload input is similiar to the folder upload input in our application.
File
<input data-automation-id="upload-multiple-files" id="upload-multiple-files" multiple="multiple" name="uploadFiles" type="file" accept="*" title="Select files to upload">
Folder
<input data-automation-id="uploadFolder" directory="" id="uploadFolder" multiple="multiple" name="uploadFiles" type="file" webkitdirectory="" accept="*" title="Select folders to upload">
For fileupload Choose File xpath=//input[@type="file"]
C:\\Users\\username\\Desktop\\robottestfile.txt
works. But for folder upload Choose File xpath=//input[@type="file"] C:\\Users\\username\\Desktop\\
doesn't.
Sorry if this has a simple solution, I have been unable to find one yet.
Tried Helios answer and it got me to a new place.
Now I have
Send folder
@{my_file_list}= OperatingSystem.List Files In Directory ${path_to_directory}
FOR ${file} IN @{my_file_list}
\ ${result}= Choose File ${my_locator} ${file}
# Finish this test
# Close Browser
*** Keywords ***
*** Variables ***
${my_locator} xpath=//input[@title="Select files to upload"]
${path_to_directory} C:\\Users\\username\\Desktop\\alfrescotestfolder
But I get this error:
ValueError: File 'alfresctotestexcel.xlsx' does not exist on the local file system.
alfrescotestexcel.xlsx is in that target folder...
Upvotes: 0
Views: 3023
Reputation: 3737
No, there is no ready made solution with Choose File
. You have to get the filenames in the folder, and then Choose File
for each.
@{my_file_list}= OperatingSystem.List Files In Directory ${path_to_directory}
: FOR ${file} IN @{my_file_list}
\ ${result}= Choose File ${my_locator} ${path_to_directory}${/}${file}
Upvotes: 2
Reputation: 538
@{my_file_list}= OperatingSystem.List Files In Directory C:\\Users\\Desktop\\My pics
FOR ${file} IN @{my_file_list}
${result}= Choose File //input[@type="file"] C:\\Users\\Desktop\\My pics\\${file}
Wait Until Keyword Succeeds 120 2s Element Should Be Visible ${xpath_for_BrowseFiles_button}
END
I have added full path in file selection. Please try these, this will work for you.
Note: If you have "Browse files" or "choose file" button then use this line Wait Until Keyword Succeeds 120 2s Element Should Be Visible ${xpath_for_BrowseFiles_button}.
Upvotes: 0