How to disable 'This type of file can harm your computer' pop up

后端 未结 8 1606
时光取名叫无心
时光取名叫无心 2020-11-27 20:43

I\'m using selenium chromedriver for automating web application. In my application, I need to download xml files. But when I download xml file, I get \'This type of file can

相关标签:
8条回答
  • 2020-11-27 21:20

    The only workaround that works for me:

    Use argument with path to chrome profile

    chromeOptions.add_argument(chrome_profile_path)
    

    Search for file download_file_types.pb in chrome profile folder. In my case ..chromedriver\my_profile\FileTypePolicies\36\download_file_types.pb

    Backup this file and then open with any hexeditor (you can use oline).

    Search for the filetype you want to download, i.e. xml and change it to anything i.e. xxx

    0 讨论(0)
  • 2020-11-27 21:21

    I used all of suggested chrome options in C# and only when my internet connected worked for me but when internet disconnected none of them work for me. (I'm not sure.may be chrome safebrowsing need to internet connection)

    By using older version of chrome(version71) and chromedriver(version 2.46) and after downloading,i saw downloaded XML file name constains 'Unconfirmed' with 'crdownload' extension and parsing XML file wouldn't work properly. Finally, creating wait with Thread.Sleep(1000) solved my problem.

                IWebDriver Driver;
    
                //chromedriver.exe version2.46 path
                string path = @"C:\cd71";
                ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(path, "chromedriver.exe");
                ChromeOptions options = new ChromeOptions();
                // options.AddArgument("headless");
                options.AddArgument("--window-position=-32000,-32000");
                options.AddUserProfilePreference("download.default_directory", @"c:\xmlFiles");
                options.AddUserProfilePreference("download.prompt_for_download", false);
                options.AddUserProfilePreference("disable-popup-blocking", "true");
                options.AddUserProfilePreference("safebrowsing.enabled", "true");
                Driver = new ChromeDriver(driverService, options);
    
                try
                {
                     Driver.Navigate().GoToUrl(url);
                     Thread.Sleep(1000);
                     //other works like: XML parse
                }
                catch
                {
    
                }
    
    0 讨论(0)
  • 2020-11-27 21:25

    Following Python code works for me

    chromeOptions = webdriver.ChromeOptions()
    prefs = {'safebrowsing.enabled': 'false'}
    chromeOptions.add_experimental_option("prefs", prefs)
    driver = webdriver.Chrome(chrome_options=chromeOptions)
    
    0 讨论(0)
  • 2020-11-27 21:29

    The accepted answer stopped working after a recent update of Chrome. Now you need to use the --safebrowsing-disable-extension-blacklist and --safebrowsing-disable-download-protection command-line switches. This is the WebdriverIO config that works for me:

    var driver = require('webdriverio');
    var client = driver.remote({
        desiredCapabilities: {
            browserName: 'chrome',
            chromeOptions: {
                args: [
                    'disable-extensions',
                    'safebrowsing-disable-extension-blacklist',
                    'safebrowsing-disable-download-protection'
                ],
                prefs: {
                    'safebrowsing.enabled': true
                }
            }
        }
    });
    

    Note that I am also disabling extensions, because they generally interfere with automated testing, but this is not strictly needed to fix the problem with downloading XML and JavaScript files.

    I found these switches by reading through this list. You can also see them in the Chromium source.

    0 讨论(0)
  • 2020-11-27 21:34

    Im using Google Version 80.0.3987.122 (Official Build) (32-bit) and ChromeDriver 80.0.3987.106. Getting the same error even after adding the below while downloading a .xml file.

    $ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
    $ChromeOptions.AddArguments(@(
        "--disable-extensions",
        "--ignore-certificate-errors"))
    
    $download = "C:\temp\download"
    $ChromeOptions.AddUserProfilePreference("safebrowsing.enabled", "true");
    $ChromeOptions.AddUserProfilePreference("download.default_directory", $download);
    $ChromeOptions.AddUserProfilePreference("download.prompt_for_download", "false");
    $ChromeOptions.AddUserProfilePreference("download.directory_upgrade", "true");
    
    $ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($chromeOptions)
    
    0 讨论(0)
  • 2020-11-27 21:36

    The problem with XML files started to happen to me as of Chrome 47.0.2526.80 m. After spending maybe 6 hours trying to turn off every possible security option I tried a different approach.

    Ironically, it seems that turning on the Chrome option "Protect you and your device from dangerous sites" removes the message "This type of file can harm your computer. Do you want to keep file.xml anyway?"

    I am using 'Ruby' with 'Watir-Webdriver' where the code looks like this:

    prefs = {
        'safebrowsing' => {
            'enabled' => true,
        }
    }
    
    b = Watir::Browser.new :chrome, :prefs => prefs
    

    Starting the browser like this, with safebrowsing option enabled, downloads the xml files without the message warning. The principle should be the same for Selenium with any programming language.

    ##### Edited: 13-04-2017

    In latest version of Google Chrome the above solution is not enough. Additionally, it is necessary to start the browser with the following switch:

    --safebrowsing-disable-download-protection
    

    Now, the code for starting the browser would look something like this:

    b = Watir::Browser.new :chrome, :prefs => prefs, :switches => %w[--safebrowsing-disable-download-protection]))
    
    0 讨论(0)
提交回复
热议问题