I'm Test Automation Engineer, working with Selenium and Java. I'm developing selenium automation tests, but I have a problem with downloading something from the software I'm working on.

Chrome asks me the security question in order to download Keep or Discard, but in selenium, as you know I cant click the Chrome window.

So I did try a few methods to get rid of this problem in Chrome, but I couldn't find a solution and this is important for me to continue to develop automation, that's why I wanted to ask if you know a solution to this issue.

I download the XML file or cer file, I get a This type of file can harm your computer pop up. I want to disable this pop up using selenium ChromeDriver and I want these types of files to be downloaded always. How can this be done?

My configuration:

  1. Chrome version:80.0
  2. Selenium version: 3.8.1
  3. Chromedriver version: 2.42

I found this code, but cap object in DesiredCapabilities doesn't work with ChromeDriver anymore;

HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("safebrowsing.enabled", "true"); 
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap); //this driver doesnt work anymore 

Any ideas?

  • 2
    Could you add an example website
    – PDHide
    Jan 6, 2021 at 10:00
  • the website I am working is in a closed network so I cant give an example but I amtrying to download .cer or .XML file. Only in chromedriver running tests, security question is asked , without chromedriver test, in the website I can download files without being asked about downloading question by manuel.
    – M S
    Jan 6, 2021 at 10:59
  • ANy website that creates similar issue like you are facing could help in giving correct answer
    – PDHide
    Jan 6, 2021 at 11:02
  • "This type of file can harm your computer. Do you want to keep ...cer anyway?" is the question is being asked while chromedriver executes test, but when ı download, it directly download. Is the any solutions for this problem I could not find anything.Thank you replying btw.
    – M S
    Jan 6, 2021 at 11:22
  • In your browser you could have disabled safe browsing where as when it launched from selenium it launch with safe browsing enabled. check with chrome://settings/security?search=safe Jan 6, 2021 at 11:35

2 Answers 2

ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("safebrowsing.enabled", true);
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);
System.setProperty("webdriver.chrome.driver", "C:\\Users\\prave\\Downloads\\chromedriver.exe");
ChromeDriver driver=new ChromeDriver(options);
WebDriverWait wait = new WebDriverWait (driver, 20);


Just use : setExperimentalOptions , safebrowsing.enabled and ("profile.default_content_settings.popups", 0);

You can use:


if you want to accept insecure cert


To hide the warning This type of file can harm your computer and enable downloading of xml type of files using Chrome/ChromeDriver you need to:

  • Add the preferences:

    • download.default_directory
    • download.prompt_for_download
    • download.extensions_to_open
    • safebrowsing.enabled
  • As well as add the following arguments to whilelist:

    • --safebrowsing-disable-download-protection
    • safebrowsing-disable-extension-blacklist
  • Code Block:

    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("download.default_directory", "C:/Utility/Downloads/");
    prefs.put("download.prompt_for_download", false);
    prefs.put("download.extensions_to_open", "application/xml");
    prefs.put("safebrowsing.enabled", true);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", prefs);
    WebDriver driver =  new ChromeDriver(options); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.