2

Despite setting safebrowsing.enabled to true / false, the warning ...This type of file can harm your computer... is still being displayed in browser. How to hide this information?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • is it while download then you may try to open the file in new tab and let user save it instead of directly downloading it – gladiator Jan 21 '20 at 11:33

1 Answers1

3

To enable downloading of file using Chrome/ChromeDriver hiding the warning This type of file can harm your computer 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

Demonstration

To demonstrate downloading using , and through I have clicked on the first Download link in the webpage http://www.landxmlproject.org/file-cabinet and your effective solution will be:

  • 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);
    options.addArguments("start-maximized");
    options.addArguments("--safebrowsing-disable-download-protection");
    options.addArguments("safebrowsing-disable-extension-blacklist");
    WebDriver driver =  new ChromeDriver(options); 
    driver.get("http://www.landxmlproject.org/file-cabinet");
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='MntnRoad.xml']//following::span[1]//a[text()='Download']"))).click();
    
  • Browser Snapshot:

Java_Chrome_Download

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for answer. Despite using listed preferences and options, Chrome still displays mentioned information. – Tomasz Wojciechowski Jan 21 '20 at 14:21
  • @TomaszWojciechowski Can't believe it. Can you update the question with your code trials please? – undetected Selenium Jan 21 '20 at 14:23
  • 1
    @DebanjabB : It was issue on specific machine. Generally, your solution works. Thank you. – Tomasz Wojciechowski Mar 03 '20 at 11:35
  • @DebanjanB I tried the above solution but still getting a download dialog box. I am trying to download one jar file and have given MIME type as application/java-archive". You marked my question as duplicate but your solution does not work. – Deepak Rai Mar 26 '20 at 03:12
  • 2
    Hi @DebanajnB your solution doesn't work in my case. I use latest chrome 80. Tried your piece of code but "This type of file can harm your computer" is still pops up and selenium is waiting until I click "Keep" –  Apr 02 '20 at 12:08
  • This solution is not working for me either, I trying to download deb file with `application/x-debian-package`MIME. Maybe reason why this solution exists - not all systems are marking xml files as unsave, for me my real, not webdriver chrome is not marking xml file as "dangerous" on Ubuntu machine – ShockwaveNN Jan 18 '21 at 14:44
  • @ShockwaveNN Why would you use a solution of downloading **`application/xml`** files for downloading your `application/x-debian-package` files? – undetected Selenium Jan 18 '21 at 18:23
  • @DebanjanB I'm not stupid, I'm not using `application/xml` in my code for downloading deb file, but I'm trying to find a solution to for same problem – ShockwaveNN Jan 19 '21 at 15:54