Selenium: Capabilities' default_directory ignored in Chrome

Created on 5 Jan 2018  路  6Comments  路  Source: SeleniumHQ/selenium

Meta

OS: Linux

Selenium Version: 3.8.1

Browser: Chrome

Browser Version: stable 62.0.3202.94

Expected Behavior

Downloads go to specified directory in capabilities' chrome prefs, which worked fine in Selenium v3.7.1 with Chromedriver: 2.33.506092

Actual Behavior

Downloads are going to file:///home/seluser/Downloads/, ignoring the capabilities' directory provided

Steps to reproduce

  1. Use Selenium Version: 3.8.1

  2. Use dart webdriver with following capabilities, and trigger a download in chrome

    Map capabilities = {
      'platform': 'LINUX',
      'browserName': 'chrome',
      'chromeOptions': {
        'args': ['window-size=1280,600', 'disable-infobars', 'enable-precise-memory-info'],
        'prefs': {
          'download': {'default_directory': '/shared/exports/', 'prompt_for_download': 'false'}
        }
      }
    }
  driver = await io.createDriver(desired: capabilities, uri: seleniumUri);

The version of Dart: Dart VM version: 1.24.2 (Thu Jun 22 15:42:21 2017) on "linux_x64"
The operating system: linux_x64
The version of the dart webdriver package: 1.2.3
The version of chromedriver: Chromedriver: 2.33.506092

C-nodejs D-chrome

Most helpful comment

Digging into this more, looks like in a selenium grid setup chromeOptions are not being matched with goog:chromeOptions. Below is the chromedriver logs from a failure:

[1526270304.899][INFO]: COMMAND InitSession {
   "capabilities": {
      "desiredCapabilities": {
         "browserName": "chrome",
         "chromeOptions": {
            "args": [ "window-size=1440,900", "disable-infobars", "enable-precise-memory-info" ],
            "extensions": [ "Q3IyNAIAAAAmAQAAAAEAADCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL+fiAlrZV+t
1lIyYR5aqiRRFdH0min2GSjrfwLCQG4tkwXa5Ml4GZRyDG8ymEcu1Xb0/sSYCZ79yzsrbBJsnLJzId/VUr
bdmqy79VbbaXqUlbGDxzf3e7OLjDmBAn23DKXg7..." ],
            "prefs": {
               "download.default_directory": "/home/seluser/exports",
               "download.prompt_for_download": false
            }
         },
         "extendedDebugging": true,
         "goog:chromeOptions": {

         },
         "platform": "LINUX",
         "seleniumProtocol": "WebDriver",
         "zal:name": "Doc: table_test.dart - Rich Text - Undo and Redo With Rich Text Fragments : linuxChrome",
         "zal:screenResolution": "1440x900"
      },
      "firstMatch": [ {
         "browserName": "chrome",
         "goog:chromeOptions": {

         },
         "platformName": "linux",
         "zal:name": "Doc: table_test.dart - Rich Text - Undo and Redo With Rich Text Fragments : linuxChrome",
         "zal:screenResolution": "1440x900"
      } ]
   },
   "desiredCapabilities": {
      "browserName": "chrome",
      "chromeOptions": {
         "args": [ "window-size=1440,900", "disable-infobars", "enable-precise-memory-info" ],
         "extensions": [ "Q3IyNAIAAAAmAQAAAAEAADCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL+fiAlrZV+t
1lIyYR5aqiRRFdH0min2GSjrfwLCQG4tkwXa5Ml4GZRyDG8ymEcu1Xb0/sSYCZ79yzsrbBJsnLJzId/VUr
bdmqy79VbbaXqUlbGDxzf3e7OLjDmBAn23DKXg7..." ],
         "prefs": {
            "download.default_directory": "/home/seluser/exports",
            "download.prompt_for_download": false
         }
      },
      "extendedDebugging": true,
      "goog:chromeOptions": {

      },
      "platform": "LINUX",
      "seleniumProtocol": "WebDriver",
      "zal:name": "Doc: table_test.dart - Rich Text - Undo and Redo With Rich Text Fragments : linuxChrome",
      "zal:screenResolution": "1440x900"
   }
}

Tweaking @seangerhardt-wf capabilities to the below settings will get things working:

Map capabilities = {
      'platform': 'LINUX',
      'browserName': 'chrome',
      'goog:chromeOptions': {
        'args': ['window-size=1280,600', 'disable-infobars', 'enable-precise-memory-info'],
        'prefs': {
          'download': {'default_directory': '/shared/exports/', 'prompt_for_download': 'false'}
        }
      }
    }
  driver = await io.createDriver(desired: capabilities, uri: seleniumUri);

Not sure if this was an intended deviation with Selenium v3.8.0/3.8.1 or not but thought I would post my findings here.

All 6 comments

+1

I have the same issue.
it works for my only in Selenium.WebDriver nuget (c#) version 3.3.0 (with chrome driver 2.27, chrome 54)

Digging into this more, looks like in a selenium grid setup chromeOptions are not being matched with goog:chromeOptions. Below is the chromedriver logs from a failure:

[1526270304.899][INFO]: COMMAND InitSession {
   "capabilities": {
      "desiredCapabilities": {
         "browserName": "chrome",
         "chromeOptions": {
            "args": [ "window-size=1440,900", "disable-infobars", "enable-precise-memory-info" ],
            "extensions": [ "Q3IyNAIAAAAmAQAAAAEAADCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL+fiAlrZV+t
1lIyYR5aqiRRFdH0min2GSjrfwLCQG4tkwXa5Ml4GZRyDG8ymEcu1Xb0/sSYCZ79yzsrbBJsnLJzId/VUr
bdmqy79VbbaXqUlbGDxzf3e7OLjDmBAn23DKXg7..." ],
            "prefs": {
               "download.default_directory": "/home/seluser/exports",
               "download.prompt_for_download": false
            }
         },
         "extendedDebugging": true,
         "goog:chromeOptions": {

         },
         "platform": "LINUX",
         "seleniumProtocol": "WebDriver",
         "zal:name": "Doc: table_test.dart - Rich Text - Undo and Redo With Rich Text Fragments : linuxChrome",
         "zal:screenResolution": "1440x900"
      },
      "firstMatch": [ {
         "browserName": "chrome",
         "goog:chromeOptions": {

         },
         "platformName": "linux",
         "zal:name": "Doc: table_test.dart - Rich Text - Undo and Redo With Rich Text Fragments : linuxChrome",
         "zal:screenResolution": "1440x900"
      } ]
   },
   "desiredCapabilities": {
      "browserName": "chrome",
      "chromeOptions": {
         "args": [ "window-size=1440,900", "disable-infobars", "enable-precise-memory-info" ],
         "extensions": [ "Q3IyNAIAAAAmAQAAAAEAADCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL+fiAlrZV+t
1lIyYR5aqiRRFdH0min2GSjrfwLCQG4tkwXa5Ml4GZRyDG8ymEcu1Xb0/sSYCZ79yzsrbBJsnLJzId/VUr
bdmqy79VbbaXqUlbGDxzf3e7OLjDmBAn23DKXg7..." ],
         "prefs": {
            "download.default_directory": "/home/seluser/exports",
            "download.prompt_for_download": false
         }
      },
      "extendedDebugging": true,
      "goog:chromeOptions": {

      },
      "platform": "LINUX",
      "seleniumProtocol": "WebDriver",
      "zal:name": "Doc: table_test.dart - Rich Text - Undo and Redo With Rich Text Fragments : linuxChrome",
      "zal:screenResolution": "1440x900"
   }
}

Tweaking @seangerhardt-wf capabilities to the below settings will get things working:

Map capabilities = {
      'platform': 'LINUX',
      'browserName': 'chrome',
      'goog:chromeOptions': {
        'args': ['window-size=1280,600', 'disable-infobars', 'enable-precise-memory-info'],
        'prefs': {
          'download': {'default_directory': '/shared/exports/', 'prompt_for_download': 'false'}
        }
      }
    }
  driver = await io.createDriver(desired: capabilities, uri: seleniumUri);

Not sure if this was an intended deviation with Selenium v3.8.0/3.8.1 or not but thought I would post my findings here.

Another important note is to set the absolute path to the directory (I tried relative path and it was ignored), I got the idea form here

Me and my colleague got around the relative path problem by converting a relative path into a absolute one.
final String path = Paths.get(".src"+File.separator+"main"+File.separator+"resources"+File.separator+"Folder1").toAbsolutePath().toString();

I got this working by setting the absolute path with a trailing \ at the end. It stops working and defaults to the default dir when going to --headless though. :/

The problem was the lack of 'goog:chromeOptions', which is needed since already several ChromeDriver versions ago. Closing as the members of the community already gave the needed feedback.

Was this page helpful?
0 / 5 - 0 ratings