Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I'm using selenium chromedriver for automating web applications. In my application, I need to download xml files. But when I download the XML file, I get '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? enter image description here

  • Selenium version: 2.47.1
  • Chromedriver version: 2.19

UPDATE its long-standing Chrome bug from 2012.

1 Answer

0 votes
by (62.9k points)

Here is a full code using Java, that got the file downloaded for me:

System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");

        String downloadFilepath = "D:/MyDeskDownload";

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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...