rshf / chromedriver

Automatically exported from code.google.com/p/chromedriver
2 stars 1 forks source link

ChromeDriver does not download files to download.default_directory value set in profile #338

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set up a Ruby on Rails application to run tests using Cucumber and Capybara 
(has Selenium built in)
2. Configure with the following:
Capybara.register_driver :chrome do |app|
  download_path = "/tmp/my_path/"
  profile = Selenium::WebDriver::Chrome::Profile.new
  profile['download.prompt_for_download'] = false
  profile['download.default_directory'] = download_path
  Capybara::Selenium::Driver.new(app, browser: :chrome, profile: profile)
end
3. Run a test that clicks a link that downloads a file

What is the expected output? What do you see instead?
The file gets downloaded to my default download directory and not the path I 
specify when setting up the profile.

Selenium version: 2.27.2
OS: Mac
Browser: Chrome
Browser version: Version 26.0.1410.65

Original issue reported on code.google.com by bobby.bl...@gmail.com on 23 Apr 2013 at 7:38

GoogleCodeExporter commented 9 years ago

Original comment by barancev on 23 Apr 2013 at 10:36

GoogleCodeExporter commented 9 years ago
Which chromedriver version do you use?

Original comment by barancev on 13 May 2013 at 10:17

GoogleCodeExporter commented 9 years ago
Hi, we are getting the same error.

Versions:
Selenium: 2.29.1.0
ChromeDriver: 2.0.204324.dyu

Original comment by mhereu@gmail.com on 14 Jun 2013 at 2:45

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hello,

I am also trying to set download location for chromedriver. Do we have some 
info here?

I am using chromedriver_win_26.0.1383.0 and chromedriver_win32_2.0

Do we have an example for each in JAVA maybe?

Original comment by jevtovic...@gmail.com on 25 Jun 2013 at 12:45

GoogleCodeExporter commented 9 years ago
Getting the same bug from python with pypi package version selenium (2.33.0)

Original comment by andres.riancho@gmail.com on 8 Aug 2013 at 2:27

GoogleCodeExporter commented 9 years ago

Original comment by st...@chromium.org on 26 Sep 2013 at 10:07

GoogleCodeExporter commented 9 years ago

Original comment by kka...@google.com on 13 Jan 2014 at 6:16

GoogleCodeExporter commented 9 years ago
Hello,

These days I upgraded Chrome to version 35 and ChromeDriver to version 2.10, 
and I found chromePreference.put("download.default_directory", "[directory]") 
(Java) is still broken. Looks like the issue above has been existing for a long 
time but no progress so far, could someone help take a look? Thanks!

Original comment by shenxie...@gmail.com on 12 Jun 2014 at 2:29

GoogleCodeExporter commented 9 years ago

Original comment by samu...@chromium.org on 21 Feb 2015 at 12:18

GoogleCodeExporter commented 9 years ago
Unable to reproduce the issue, and "download.default_directory", "[directory]" 
works good. please let me know if issue is still existing with latest version 
of ChromeDriver(2.15), Chrome(41.xx.xx.xx) And Selenium(2.45)

---- tried with----------------
     DesiredCapabilities caps = DesiredCapabilities.chrome();

     ChromeOptions options = new ChromeOptions();
     Map<String, Object> prefs = new HashMap<String, Object>();
     prefs.put("download.default_directory", "/usr/local/path/to/download/directory");
     options.setExperimentalOption("prefs", prefs);
     caps.setCapability(ChromeOptions.CAPABILITY, options);

     WebDriver driver = new ChromeDriver(caps);
     driver.get("http://www.seleniumhq.org/download/");
     driver.findElement(By.xpath("html/body/div/div[2]/div[2]/p[3]/a")).click();

Original comment by agau...@chromium.org on 10 Apr 2015 at 10:56

ghost commented 9 years ago

This issue still exists. Capybara.register_driver:selenium do|app| profile = Selenium::WebDriver::Chrome::Profile.new profile['download.prompt_for_download'] = false profile['download.default_directory'] = download_directory
Capybara::Selenium::Driver.new(app, :browser => :chrome,:profile => profile) end Error is Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/response.rb:71:in `assert_ok': unknown error: cannot parse capability: chromeOptions (Selenium::WebDriver::Error::UnknownError) from unknown error: unrecognized chrome option: profile

(Driver info: chromedriver=2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961),platform=Windows NT 6.1 SP1 x86_64)

lcamhoa commented 7 years ago

I found that the "download.default_directory" should be an absolute and existed path. Can all of you check again ? It worked for me.

0xdeadfa11 commented 7 years ago

Hello! You should remove trailing slash on download.default_directory path. I don't know why, but it's critical for ChromeDriver.

igrishaev commented 6 years ago

The issue is still there.

ChromeDriver 2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262)
Mac OS 10.11.6

Faced it when writing my own library for browser automation.

igrishaev commented 6 years ago

My capabilities were:

{:desiredCapabilities {:loggingPrefs {:browser "ALL"}, 
 :chromeOptions {:prefs {:download.default_directory "/Users/ivan/Desktop",
                         :download.prompt_for_download false,
                         :profile.default_content_settings.popups 0}}}}
omkarnathsingh commented 5 years ago

Any update on this?

2kiranns commented 5 years ago

Any update on this? I still face the same problem.

Here's the excerpt: Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 21856 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument: cannot parse capability: goog:chromeOptions from invalid argument: unrecognized chrome option: download.default_directory (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)

Options I have set: ChromeOptions options = new ChromeOptions(); options.addArguments("--start-maximized"); options.setExperimentalOption("profile.default_content_settings.popups", 0); options.setExperimentalOption("download.default_directory", "D:\\Selenium\\download"); options.setExperimentalOption("download.prompt_for_download", false); options.setExperimentalOption("download.directory_upgrade", true); options.setExperimentalOption("safebrowsing.enabled", true); this.driver = new ChromeDriver(options);

DanVill29 commented 5 years ago

hi Guys.. im also encountering this issue. Any updates on this?

domgia commented 5 years ago

I'm also seeing this, there was a bug open in the issue tracker but it looks like it disappeared.

joaodematejr commented 5 years ago

+1

chandanijain9 commented 5 years ago

Facing the same issue with latest version of chrome : Version 75.0.3770.100 Any help is appreciated !!

valentyn-red-bird commented 5 years ago

If you are using Windows 10 you must specify an explicit folder path in Windows notation. For example, in java this will be look like "C:\\Selenium\\autotest-project\\downloads". Do not forget to use two \. In such case I have it worked with the latest chrome.

adityabhargav commented 4 years ago

I found that the "download.default_directory" should be an absolute and existed path. Can all of you check again ? It worked for me.

--- is it not possible with relative path in the project... for me able to get working with absolute path , but relative path its failing... Kindly, Check and help us with it Thanx in advance.

adityabhargav commented 4 years ago

hey folks, got the soution by placing.... ' ${user.home} ' for the relative path in the .properties file..

Will work 100%..

ex:- chrome_preferences.download.default_directory=${user.home}//Desktop//appium//src//main//resources//pathToData

happy1610 commented 4 years ago

hey folks, got the soution by placing.... ' ${user.home} ' for the relative path in the .properties file..

Will work 100%..

ex:- chrome_preferences.download.default_directory=${user.home}//Desktop//appium//src//main//resources//pathToData

you save my day 💃

sb1129 commented 4 years ago

My selenium helper for chrome browser ---

                final ChromeOptions options = new ChromeOptions();
                HashMap<String, Object> chromePref = new HashMap<>();
                options.addArguments("--incognito", "--disable-popup-blocking", "safebrowsing-disable- 
                download-protection", "allow-unchecked-dangerous-downloads");
                //to provide download location if any
                chromePref.put("profile.default_content_settings.popups", 0);
                chromePref.put("download.default_directory", DOWNLOAD_LOCATION_PATH);
                //chromePref.put("download.extensions_to_open", "EML");
                chromePref.put("safebrowsing.enabled", false);
                //chromePref.put("useAutomationExtension", false);
                chromePref.put("download.prompt_for_download", false);
                chromePref.put("download.directory_upgrade", true);
                options.setExperimentalOption("prefs", chromePref);
                driver = new ChromeDriver(options);

I am still unable to fix the problem of warning message "this file can harm my computer" with keep and discard button. I tried the download path changing from user.dir to user.home, doesn't help.

archanachaudhari2710 commented 4 years ago

i have same problem Caused by: org.openqa.selenium.InvalidArgumentException: invalid argument: entry 0 of 'firstMatch' is invalid from invalid argument: cannot parse capability: goog:chromeOptions from invalid argument: unrecognized chrome option: desiredCapabilities.chromeOptions.prefs.download.default_directory Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info:, os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_212' Driver info: driver.version: ChromeDriver remote stacktrace: Backtrace:

i have tried below properties desiredCapabilities.chromeOptions.prefs.download.default_directory chromeOptions.prefs.download.default_directory prefs.download.default_directory download.default_directory

path is also correct

Warlib1975 commented 4 years ago

I have the same problem. Try to use all approaches mentioned here. :-(

gdom12345 commented 4 years ago

I've found that chromedriver cannot create the folder if it doesn't exist, and manually adding the folder solved the inability to download.

Warlib1975 commented 4 years ago

I've found that chromedriver cannot create the folder if it doesn't exist, and manually adding the folder solved the inability to download.

Yes, I found the mistake. It was the wrong folder. Thank you. Now everything is downloading fine.

shonaalok commented 4 years ago

In my case , I am not getting any error but the file is downloaded to default download location. I have used existing directory but it just does not work.Chrome version :83 and 77 ( MAC) and 78 (windows) Map<String, Object> prefs = new HashMap<String, Object>();

Method 1 : File folder = new File(UUID.randomUUID().toString()); folder.mkdir(); prefs.put("download.default_directory", folder.getAbsolutePath()); Method 2: prefs.put("download.default_directory", System.getProperty("user.dir")+ File.separator + "externalFiles" + File.separator + "downloadFiles"); Method 3: String path = "/Users//Documents" prefs.put("download.default_directory", path);

Common code: ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); capabilities.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(capabilities);

Mintaka commented 3 years ago

One of the reasons why you can't set your value in to "download.default_directory" may be that you have a system variable XDG_DOWNLOAD_DIR in file ~/.config/user-dirs.dirs because chromedriver, unpredictable, prior that settings.

My SW set:

Soniakaushik commented 3 years ago

hi Folks, I'm facing same issue after tried the above changes to my code. I think this issue is still open. If not, please help me out.

Thanks in advance

eckeskin commented 3 years ago

I am also stuck with that problem. I couldn't proceed. Even I tried above mentioned configuration, I still get an error. Any improvements or suggestions?

Hariks21 commented 2 years ago

My problem is not able to download the file using chrome latest version in windows10 machine And I am using webdriverIO Problem: When I click on download link it just open in a new tab and stays there

Here is my configuration file: browserName: 'chrome', acceptInsecureCerts: true, 'goog:chromeOptions':{ args: [ '--window-size=2600,1800', //'--headless', '--allow-http-background-page', '--allow-running-insecure-content', '--allow-insecure-localhost', '--no-sandbox', '--disable-dev-shm-usage', '--disable-infobars', '--disable-web-security', '--disable-popup-blocking' ], prefs : { 'download.prompt_for_download' : false, 'download.directory_upgrade': true, 'download.default_directory' : pathToDownload, 'profile.managed_default_content_settings.popups': 0, 'profile.managed_default_content_settings.notifications': 1, 'profile.content_settings.exceptions.automatic_downloads.*.setting': 1, 'safebrowsing.enabled': true, } },