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 (e.g. in case of http://selenium.googlecode.com/files/selenium-server-standalone-2.33.0.jar)
  3. Give the desired location to save that file.

Any suggestions??

Apr 13, 2018 in Selenium by Meci Matt
• 9,420 points
6,412 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");
answered Apr 13, 2018 by Meci Matt
• 9,420 points

Related Questions In Selenium

+1 vote
1 answer
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
576 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
898 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
565 views
0 votes
1 answer
0 votes
1 answer