Reputation: 1135
We've a web application wherein it uploads attachments ( Files - JPG , PDF or any other ). Right now to upload these files, the files need to be kept in folder : C:\Users\username so that the chrome browser automatically uploads them during test automation execution.
We want to upload JPG files from a custom and generic folder so that upload is independent of the path. Is there any way wherein we specify the chrome to choose a specific folder to upload these files ( ex : To upload files from folder C:\TestData ) independent of the user logged in ?
So my issue is how to set the default file upload path in Chrome Browser so that all the files can be picked-up for uploading from that default directory (folder).
My Attempt:
After the relaunch of the chrome browser through script, still it continued to refer to C:\Users\username rather than custom path specified in chrome settings.
Screenshot attached below for reference.
Upvotes: 0
Views: 2029
Reputation: 20057
Every time selenium starts a browser, it does so with a new profile - thus when you change the settings in it, they are not present the next time the automation is ran.
Here's how to set the browser's download location - the folder where any streamed is saved (I'm stressing in this, cause you seem to use upload/download interchangeably). You create a special dictionary of settings, and pass that when creating the driver:
${chromeOptions}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${prefs} = Create Dictionary download.default_directory=c:\\your\\directory
Call Method ${chromeOptions} add_experimental_option prefs ${prefs}
Open Browser Chrome options=${chromeOptions}
Obviously, the setting you are looking for is the download.default_directory
one.
Upvotes: 1
Reputation: 375
Finally found a solution using Open Browser Keyword to change the download directory
${prefs} = Create Dictionary download.default_directory=C:\\Balaji
Open Browser https://www.google.com/ chrome
options=add_experimental_option("prefs",${prefs})
Maximize Browser Window
Set Browser Implicit Wait 20
Upvotes: 0