0

My issue is when i pass profile as an option:

            options.add_argument("--user-data-dir=C:\\Users\\shimon\\AppData\\Local\\Google\\Chrome\\User Data")
        options.add_argument("--profile-directory=Profile 3")

The download set path seems to take no affect

            prefs = {"download.default_directory": "C:\\Users\\shimon\\PycharmProjects\\project_2\\downloaded\\files"}
        options.add_experimental_option("prefs", prefs)

If I remove the profile

            options.add_argument("--profile-directory=Profile 3")

It works well. Is there any solution for that? couldn't find any related issue.

1 Answers1

1

You might try the following:

options = ChromeOptions()
current_directory = os.getcwd()
download_directory = f"{current_directory}/temp"

prefs = {
    "download.default_directory": download_directory,
    "download.prompt_for_download": False,  # To auto download the file
    "download.directory_upgrade": True,
    "plugins.always_open_pdf_externally": True,
}  # It will not show PDF directly in chrome}
options.add_experimental_option("prefs", prefs)
options.add_argument("--headless")

driver = # initialize driver

if not os.path.exists(download_directory):
    os.makedirs(download_directory)

params = {"behavior": "allow", "downloadPath": download_directory}
driver.execute_cdp_cmd("Page.setDownloadBehavior", params)

also, you should check:

  1. If replacing \\ with / in your path works (noticed that issue on Windows sometimes)
  2. If the Path exists and has the correct permissions
kaliiiiiiiii
  • 925
  • 1
  • 2
  • 21