Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

Disable chrome download multiple files confirmation

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 );


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...