Skip to content

[🐛 Bug]: Cannot Set Custom Download Directory in Selenium 4.27.0 #14886

@maldanus

Description

@maldanus

What happened?

When attempting to set a custom download directory using the download.default_directory preference in Selenium, the setting is always overwritten to /home/user/Downloads. I have tried multiple directory paths including:

/tmp/

Project root directory

Subfolders within the project

How can we reproduce the issue?

Environment:

Selenium Version: 4.27.0

Java Version: 17

Operating System: Xubuntu 24

ChromeDriver Version: 131.0.6778.87

Chromium Version: 131.0.6778.87

Map<String, Object> prefs = new HashMap<>();
prefs.put("download.default_directory", downloadFilePath);
prefs.put("download.prompt_for_download", false);
prefs.put("download.directory_upgrade", true);
prefs.put("safebrowsing.enabled", true);
options.setExperimentalOption("prefs", prefs);



Expected Behavior:

The browser should use the specified download.default_directory for file downloads.

Actual Behavior:

The download directory is always set to /home/user/Downloads, ignoring the specified download.default_directory.

Steps to Reproduce:

Create a Selenium project using Java and include the above configuration for ChromeOptions.

Specify a custom download directory (e.g., /tmp/ or a project subfolder).

Run the test and observe the download location.

Additional Information:

Verified that the downloadFilePath variable contains a valid absolute path.

Tested with different paths, but the issue persists.

Other preferences (e.g., safebrowsing.enabled) are applied successfully.

Request:

Please investigate if this is a bug or if there are additional steps required to ensure the download.default_directory setting is applied correctly. Let me know if further details or logs are needed.

Relevant log output

[1733864025.508][INFO]: Starting ChromeDriver 131.0.6778.87 (ce31cae9487357cfd3bd62984ed5250121a71a23-refs/branch-heads/6778@{#2287}) on port 24175
[1733864025.508][INFO]: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1733864025.509][INFO]: ChromeDriver was started successfully on port 24175
[1733864025.581][INFO]: [e0093efdaa4cda4c8ae9d2d775f00db4] COMMAND InitSession {
   "capabilities": {
      "firstMatch": [ {
         "browserName": "chrome",
         "goog:chromeOptions": {
            "args": [ "--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu", "--disable-extensions", "--disable-infobars", "--disable-notifications", "--user-data-dir=ProjectDirServer/files/chromeProfile" ],
            "binary": "selenium/chrome-linux64/chrome",
            "extensions": [  ],
            "prefs": {
               "download.default_directory": "/tmp/down",
               "download.directory_upgrade": true,
               "download.prompt_for_download": false,
               "safebrowsing.enabled": true
            }
         }
      } ]
   },
   "desiredCapabilities": {
      "browserName": "chrome",
      "goog:chromeOptions": {
         "args": [ "--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu", "--disable-extensions", "--disable-infobars", "--disable-notifications", "--user-data-dir=ProjectDirServer/files/chromeProfile" ],
         "binary": "selenium/chrome-linux64/chrome",
         "extensions": [  ],
         "prefs": {
            "download.default_directory": "/tmp/down",
            "download.directory_upgrade": true,
            "download.prompt_for_download": false,
            "safebrowsing.enabled": true
         }
      }
   }
}
[1733864025.581][INFO]: Populating Preferences file: {
   "alternate_error_pages": {
      "enabled": false
   },
   "autofill": {
      "enabled": false
   },
   "browser": {
      "check_default_browser": false
   },
   "distribution": {
      "import_bookmarks": false,
      "import_history": false,
      "import_search_engine": false,
      "make_chrome_default_for_user": false,
      "skip_first_run_ui": true
   },
   "dns_prefetching": {
      "enabled": false
   },
   "download": {
      "default_directory": "/tmp/down",
      "directory_upgrade": true,
      "prompt_for_download": false
   },
   "profile": {
      "content_settings": {
         "pattern_pairs": {
            "https://*,*": {
               "media-stream": {
                  "audio": "Default",
                  "video": "Default"
               }
            }
         }
      },
      "default_content_setting_values": {
         "geolocation": 1
      },
      "default_content_settings": {
         "geolocation": 1,
         "mouselock": 1,
         "notifications": 1,
         "popups": 1,
         "ppapi-broker": 1
      },
      "password_manager_enabled": false
   },
   "safebrowsing": {
      "enabled": true
   },
   "search": {
      "suggest_enabled": false
   },
   "translate": {
      "enabled": false
   }
}

Operating System

Xubuntu 24

Selenium version

Java 4.27.0

What are the browser(s) and version(s) where you see this issue?

ChromeDriver Version: 131

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver Version: 131.0.6778.87

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-defectSomething is not working as intendedI-questionApplied to questions. Issues should be closed and send the user to community resources.J-issue-templateApplied to issues not following the template, or missing information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions