Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to download file using ChromeDriver

I am using chromedriver with selenium to download files from application. But while clicking on download button in application, it given error as "Failed-Download error."

Chromedriver version : 2.21 Selenium version : 2.53.0

Code for initializing chrome driver and changing download location :

            String newPath = "D:\\Backup" + File.separator + "Database ";
            new File(newPath).mkdir();
            HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
            chromePrefs.put("profile.default_content_settings.popups", 0);
            chromePrefs.put("download.default_directory", newPath);
            chromePrefs.put("safebrowsing.enabled", "true");
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", chromePrefs);
            options.addArguments("--test-type");
            DesiredCapabilities cap = DesiredCapabilities.chrome();
            cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            cap.setCapability("disable-popup-blocking", true);
            cap.setCapability(ChromeOptions.CAPABILITY, options);
            System.setProperty("webdriver.chrome.driver", CHROME_DRIVER_PATH);
            driver = new ChromeDriver(cap);
            // Maximize the driver window
            driver.manage().window().maximize();

Error is :

enter image description here

Can someone help me with this? I am able to download file from Chrome manually.

like image 658
Mosam Mehta Avatar asked May 19 '16 09:05

Mosam Mehta


1 Answers

In my case I had something similar, but the error was in the folder name I used. I describe the path as C:/myFolder instead of C:\myFolder.

In previous version of ChromeDriver the first approach was still valid. Now it looks like this is not working anymore giving some Download error.

like image 96
Marco smdm Avatar answered Sep 29 '22 11:09

Marco smdm