Downloading and Saving a file to a desired location using Selenium Webdriver

0 votes

Following are my requirements:

  1. Click on any link/button that start downloading any file
  2. Click on the "Save" on popup if appeared 
  3. Give the desired location to save that file.

Any suggestions??

Apr 13, 2018 in Selenium by Meci Matt
• 9,460 points
32,161 views

1 answer to this question.

0 votes

You can set the default download location for the browser, but you won’t be able to access the save dialog box as it is controlled by operating system.

When setting up your Firefox profile you add a call to set the property browser.helperApps.neverAsk.saveToDisk to a comma separated list of MIME types to always download:

firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");

FirefoxProfile firefoxProfile = new FirefoxProfile();

firefoxProfile.setPreference("browser.download.folderList",2);

firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);

firefoxProfile.setPreference("browser.download.dir","c:\\downloads");

firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");

WebDriver driver = new FirefoxDriver(firefoxProfile);//new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);

driver.navigate().to("http://www.myfile.com/hey.csv");

For further understanding, you can refer to the Selenium Training.

answered Apr 13, 2018 by Meci Matt
• 9,460 points

Related Questions In Selenium

+1 vote
1 answer
0 votes
5 answers
0 votes
1 answer
0 votes
1 answer

How to extract text from a web page using selenium and save it as a text file?

Hello Isha, you can checkout this code ...READ MORE

answered May 7, 2019 in Selenium by Anvi
• 14,150 points
34,833 views