Reputation: 21
I need to download XLSX files using Java + Selenium in chrome, but I'm not able to choose the folder to download the files. I've tried all the other alternatives I found here, but from what I've noticed, all the others are already obsolete. Here is my code:
String downloadFilepath = "D:\\down\\";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("prompt_for_download", false);
chromePrefs.put("directory_upgrade", true);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--disable-notifications");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver = new ChromeDriver(options);
Upvotes: 0
Views: 1165
Reputation: 21
I managed to resolve it. I downloaded the last stable version that came out in July (mine was from June) of chromedriver and put the code below.
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
WebDriver driver = new ChromeDriver(options);
Upvotes: 2