Disable chrome download multiple files confirmation
Asked Answered
U

9

19

I developed a crawler with ruby watir-webdriver that downloads some files from a page. My problem is that when I click to download the second file, Chrome opens a bar in the top asking for confirmation that I am downloading multiple files from this website.

Once this is used by webdriver, I cannot confirm the download. Is there anyway to avoid this confirmation? I am thinking if is there any configuration to avoid it or if is there an extension to do this or even if I can click on the confirmation with webdriver.

thanks

Ulcerous answered 4/4, 2013 at 17:2 Comment(0)
K
21

I'm using Chrome 49 and none of the other solutions worked for me. After some research I found a working solution:

ChromeDriver createChromeDriverWithDownloadFolder(String folder) {
    Map<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", folder);
    chromePrefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1 );
    chromePrefs.put("download.prompt_for_download", false);

    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(cap);
}

It seems as if these settings are constantly changing. Therefore, here's how I found the right solution for my setup:

  1. Open Chrome and go to chrome://version/ to find the path of your profile
  2. In Default/Preferences is a json file called Preferences. Open it and search for automatic_downloads. In my case the interesting part of the file looked like this:

    ..."profile": { "avatar_bubble_tutorial_shown": 1, "avatar_index": 0, "content_settings": { "clear_on_exit_migrated": true, "exceptions": { "app_banner": {}, "auto_select_certificate": {}, "automatic_downloads": { "[.]localhost:63342,": { "setting": 1 },...

  3. From that I could derive that the right setting would be chromePrefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1 );

Koral answered 24/4, 2016 at 8:59 Comment(3)
Thanks. Given solution worked for me on chrome 51 and chrome driver 2.20.Piperidine
Thanks it worked for me on the latest chrome browser and chrome driver versionInfare
it is throwing bad_variant_access error for me, I am using puppeteer to launch chromium & download something from website.Benadryl
E
12

As of Chrome 56.0.2924.87, February 17, 2017, the only preference you need to set (however you set them for your webdriver) is:

'profile.default_content_setting_values.automatic_downloads': 1

Giving an updated answer because most answers here use outdated preferences or show other preferences that are unnecessary.

Empower answered 14/2, 2017 at 22:29 Comment(3)
FYI.. this setting/option is still working with the newest Chrome version i.e.Version 83.0.4103.116 (Official Build) (64-bit). Tried and tested.Puett
this one works for meBenadryl
And apparently it's stopped working :|Alfaro
I
7

for new chrome (version 46 or newer) this options was changed now your hash must looks like this:

prefs = {
    'profile' => {
        'default_content_settings' => {'multiple-automatic-downloads' => 1}, #for chrome version olde ~42
        'default_content_setting_values' => {'automatic_downloads' => 1}, #for chrome newer 46
    }
}

browser = Watir::Browser.new :chrome, options: {prefs: prefs, args: ['--test-type', '--disable-infobars'}
Incuse answered 15/10, 2015 at 15:13 Comment(2)
This solution worked for me, but broke how I was originally handling browser window sizing. Is there a site that lists ALL the changes one can make?Demarcation
This solution is working in version 66 using chromedriver in selenium with perl.Understanding
P
3

Here is the solution for Java - Selenium implementation

We faced hard time fixing this, as we wanted to add automation test for functionality which downloads set of PDFs on a single download link.

Map<String, Object> prefs = new HashMap<String, Object>();
//To Turns off multiple download warning
prefs.put("profile.default_content_settings.popups", 0);
prefs.put( "profile.content_settings.pattern_pairs.*.multiple-automatic-downloads", 1 );
//Turns off download prompt
prefs.put("download.prompt_for_download", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOptions("prefs", prefs);
driver =  new ChromeDriver(options);

Hope this help to someone.

Piperidine answered 19/1, 2016 at 12:16 Comment(2)
Do you have a javascript version? Of can I even do that from client-side using Javascript? All I need is setting multiple-automatic-downloads" to 1 (true) !! Because I do not want to see the prompt asking it.Bradney
No I dont have javascript version. Not sure but it should be possible.Piperidine
S
2

It seems that the solution is different for older and newer chromedriver versions and that is adding to the confusion.

chromedriver

profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = download_directory

b = Watir::Browser.new :chrome, :profile => profile

chromedriver2

prefs = {
      'profile' => {
          'default_content_settings' => {'multiple-automatic-downloads' => 1},
      }
  }

b = Watir::Browser.new :chrome, :prefs => prefs

Today most people are probably using chromedriver2 version and that is a solution that should work fine. It worked ok in my watir scripts as I am not getting the message: "This site is attempting to download multiple files. Do you want to allow this?" anymore.

Saccharoid answered 5/3, 2015 at 13:24 Comment(0)
T
1

Java solution:

cap = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
Map<String, Object> content_setting = new HashMap <>();

content_setting.put("multiple-automatic-downloads",1);

prefs.put("download.prompt_for_download", "false");
prefs.put("profile.default_content_settings", content_setting);

options.setExperimentalOption("prefs", prefs);
cap.setCapability(ChromeOptions.CAPABILITY, options);
Tyishatyke answered 27/4, 2015 at 16:43 Comment(0)
G
1

this is what worked for me:

HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("profile.default_content_setting_values.automatic_downloads", 1);
chromePrefs.put("download.prompt_for_download", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
Gaspard answered 25/10, 2016 at 14:22 Comment(0)
B
0

This bug/enhancement has been raised in the chromedriver page at the below URL: http://code.google.com/p/chromedriver/issues/detail?id=130

Bug/Enhancement Status: Yet to be resolved.

Binnie answered 20/5, 2013 at 5:47 Comment(1)
Did you get any solution of it?Buxton
B
0

I have tried to do it on page load client-side using markups.

<META HTTP-EQUIV="Content-Disposition" CONTENT="inline" />

It seems to work (it is working at this moment, in overriding).

But time will tell (might not have effect on future CHROME's, you know what I mean).

There are a list of available header fields published on a couple of sites which I find extremely helpful. Hope it will help you, as well.

https://www.w3.org/Protocols/HTTP/Issues/content-disposition.txt https://www.iana.org/assignments/cont-disp/cont-disp.xhtml#cont-disp-2

Bradney answered 26/1, 2018 at 19:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.