Selenium Webdriver in Python - files download directory change in Chrome preferences

前端 未结 6 1595
逝去的感伤
逝去的感伤 2020-11-27 05:09

I\'m using Selenium Webdriver (in Python) to automate the downloading of thousands of files. I want to set Chrome\'s download folder programmatically. After reading this, I

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 05:43

    If anyone is still having trouble and the above solutions didn't work, I found adding a following slash ('\') to my download path.

    Mine looked like this:

        if browser == 'chrome':
            options = webdriver.ChromeOptions()
            options.add_argument("--start-maximized")
            prefs = {"profile.default_content_settings.popups": 0,
                     "download.default_directory": r"C:\Users\user_dir\Desktop\\", # IMPORTANT - ENDING SLASH V IMPORTANT
                     "directory_upgrade": True}
            options.add_experimental_option("prefs", prefs)
            return webdriver.Chrome(executable_path=Base.chromedriver_dir, chrome_options=options)
    

提交回复
热议问题