Wednesday, 23 August 2023

Workaround fix to specify custom download path for ChromeDriver 114 or Browser 114, Selenium 4.11.0

Hi, The following questions and the fix is a work around to download the file to a custom folder in with chrome driver/browser with 114 version 

  1. Are you getting asked to Save the file while trying to download in Incognito mode? 
  2. Does the file download to "Downloads" folder by default in non incognito mode ?  
  3. Are you seeing in consistent behavior to download a file using ChromeDriver 114 ?   


The work around fix worked for me is to keep the browser in headless mode with --headless=old so the file will download to custom path specified. 

final static String downloadPath = "C\\Automation\\downloads;
HashMap<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("download.default_directory", downloadPath);

System.out.println(chromePrefs.get("download.default_directory"));
ChromeOptions options = new ChromeOptions();

options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--headless=old");
driver.set(new ChromeDriver(options));

 References: 

https://stackoverflow.com/questions/76175638/unable-to-change-default-download-directory-for-chrome-selenium-instance-linux

https://github.com/SeleniumHQ/selenium/issues/11637

No comments:

Post a Comment