-1

I have changed the path of file download from using below code.

chromeOptions=Options()
chromeOptions.add_experimental_option("prefs", {"download.default_directory":  r"C:\Users\Ads\downloadfolder", "download.prompt_for_download": False,
  "download.directory_upgrade": True,
  "safebrowsing.enabled": True})
driver = webdriver.Chrome(options=chromeOptions)     

I have developed 29 different scripts to download different documents from different web applications. I have put above code in all the scripts but I want to define it at one place and use across all the scripts. It will help me to change the download path at once if required instead of changing it by editing all the scripts.

  • i guess, create a method that returns chrome option : – PDHide Jun 29 at 9:24
  • driver = webdriver.Chrome(options=setup.GetOptions()) – PDHide Jun 29 at 9:24
  • I tried using new python file and call it in script file but its downloading to download file which is default of chrome and not to my defined file. – Amaze_Rock Jun 29 at 9:27
  • add what you have tried and failed – PDHide Jun 29 at 9:27
  • I have created one python file using above code. chromeOptions=Options() chromeOptions.add_experimental_option("prefs", {"download.default_directory": r"C:\Users\Ads\downloadfolder", "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True}) driver = webdriver.Chrome(options=chromeOptions) and then called it in my script as driver = webdriver.Chrome(chromeOptions=Options()) – Amaze_Rock Jun 29 at 9:39
0

Create a file say Setup.py in package say common:

with below content

def getOptions():
    chromeOptions=Options()
    chromeOptions.add_experimental_option("prefs", {"download.default_directory":  r"C:\Users\Ads\downloadfolder", "download.prompt_for_download": False, "download.directory_upgrade": True   "safebrowsing.enabled": True})
    return chromeOptions

And when ever you are creating driver in the test scripts add below import:

from common import Setup

and now call option in the test script as

driver = webdriver.Chrome(options=Setup.getOptions())     
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.