[Python] Unable to change default download directory for chrome selenium instance...

Discussão em 'Python' iniciado por Stack, Julho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have a webdriver running with the following configs:

    options.add_argument("--kiosk-printing")
    options.add_argument("--print-to-pdf")

    prefs = {
    "download.default_directory": download_path,
    "download.prompt_for_download": False,
    "download.directory_upgrade": True,
    "safebrowsing_for_trusted_sources_enabled": False,
    "safebrowsing.enabled": False}
    options.add_experimental_option('prefs', prefs)


    I set the download_path to an existing directory. When the browser runs I even open the chrome://settings/downloads page to check the path and it does indeed show that my default download directory is the one I set. However when I try to save anything the prompt does not point to that folder, instead pointing to the default downloads directory.

    The kicker is if I manually change the download directory in the chrome instance it does work, even though I'm setting it to the exact same folder that it was saying it was pointing to.

    Am I doing something wrong? Not sure why it says that the directory is set but not actually doing it even though it's reflected in the Chrome settings.

    EDIT: Possible solution that worked for me. I rummaged through my chrome settings file and found the preferences file that holds all your settings.

    For some reason, download.default_directory only affects the visual representation of your download path. When you manually change the download directory, it adds another object to your settings dict savefile.default_directory with the exact same information. But this one actually affects where the download is stored.

    I don’t know why or what the heck is up with this, but it seems to work.

    Continue reading...

Compartilhe esta Página