Disable chrome download multiple files confirmation

后端 未结 9 1410
太阳男子
太阳男子 2020-12-02 01:57

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

9条回答
  •  独厮守ぢ
    2020-12-02 02:18

    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 chromePrefs = new HashMap();
        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 );

提交回复
热议问题