0

I have tried a lot to set a custom path for downloads while using webdriver-manager 3.8.4 for my script. Whenever my script tries to download a file, the download keeps failing. I do not get any error in the console which makes it worse.
The steps I tried to fix my problem:

  • Update chrome browser
  • Reinstall webdriver-manager 3.8.4
  • Try a different location
  • Manually click on download while the script runs

None of them seems to work. However, the default download location has no issues.
My main concern is how do I set a custom download path with webdriver-manager in Selenium python?

new_dir = r"D:/Selenium/Insights/" + datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
        print(new_dir)
        if not os.path.exists(new_dir):
            #pass
            os.makedirs(new_dir)
        prefs = {"download.default_directory": new_dir, "download.directory_upgrade": True}
        print(prefs)
        options=Options()
        options.add_argument('--start-maximized')
        options.add_experimental_option("prefs", prefs)
        self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
Libin Thomas
  • 829
  • 9
  • 18
  • try with just: prefs = {"download.default_directory": new_dir} The download.directory_upgrade bit isn't needed. Also make sure those slashes are correct. OS? When you say the download fails can you give more details? Watch the directory you are creating to see if the ".crdownload" file appears while the script is running. If so, it may just be that the browser is closed before the download is completed. If the directory is not created, you might need to set "exist_ok" argument for makedirs... see here: https://docs.python.org/3/library/os.html#os.makedirs – pcalkins Oct 18 '22 at 22:36
  • I tried with a backward slash as well. Didn't work at all. Is it because I am using webdriver-manager and not the ```chromdriver.exe``` file? – Libin Thomas Oct 19 '22 at 10:35
  • need more details... debug a bit... try/catch the call... see if the directory is created and if permissions are correct for the browser/user. – pcalkins Oct 19 '22 at 16:33
  • 1
    @pcalkins you were right about the directory name formatting. I tried the syntax ```new_dir = r"D:\Selenium\Insights\{timestamp}".format(timestamp=datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))``` and now it works well. – Libin Thomas Oct 19 '22 at 17:05

0 Answers0