How to control the download of files with Selenium + Python bindings in Chrome

后端 未结 2 1072
小鲜肉
小鲜肉 2020-11-29 07:52

Where can I find the documentation that describes the options I can use with Selenium and Chrome web browser? I want to open a link in a web browser (to get credential) but

相关标签:
2条回答
  • 2020-11-29 08:23

    The path you declared for the default directory is invalid. Either escape the back slashes or provide a literal string.

    options = webdriver.ChromeOptions()
    options.add_experimental_option("prefs", {
      "download.default_directory": r"C:\Users\xxx\downloads\Test",
      "download.prompt_for_download": False,
      "download.directory_upgrade": True,
      "safebrowsing.enabled": True
    })
    driver = webdriver.Chrome(chrome_options=options)
    

    Here are the available preferences:

    https://cs.chromium.org/chromium/src/chrome/common/pref_names.cc

    0 讨论(0)
  • 2020-11-29 08:29

    It makes all the difference in the world to use the forward slash "/" when specifying the directory in which you want things to be downloaded.

    I'm guessing this is because that directory will be exported to something like the Powershell, where the usual backslash "\" won't properly work.

    0 讨论(0)
提交回复
热议问题