- Create a FireFox Profile.
- Set Preferences as per requirement.
- Open Firefox with FireFox Profile.
Let us implement the same through Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.qaearth; | |
import org.openqa.selenium.Capabilities; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.firefox.FirefoxProfile; | |
import org.testng.annotations.BeforeTest; | |
public class DownloadingFile { | |
WebDriver driver; | |
@SuppressWarnings("deprecation") | |
@BeforeTest | |
public void StartBrowser() { | |
// Create object of FirefoxProfile in built class to access Its | |
// properties. | |
FirefoxProfile fprofile = new FirefoxProfile(); | |
// Set Location to store files after downloading. | |
fprofile.setPreference("browser.download.dir", "D:\\WebDriverdownloads"); | |
fprofile.setPreference("browser.download.folderList", 2); | |
// Set Preference to not show file download confirmation dialogue using | |
// MIME types Of different file extension types. | |
fprofile.setPreference("browser.helperApps.neverAsk.saveToDisk", | |
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"// MIME | |
// Excel | |
+ "application/pdf;" // MIME types Of PDF File. | |
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document;" // MIME// Doc | |
+ "text/plain;" // MIME types Of text File. | |
+ "text/csv"); // MIME types Of CSV File. | |
fprofile.setPreference("browser.download.manager.showWhenStarting", false); | |
fprofile.setPreference("pdfjs.disabled", true); | |
// Pass fprofile parameter In webdriver to use preferences to download | |
// file. | |
driver = new FirefoxDriver((Capabilities) fprofile); | |
} | |
} |

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void OpenURL() throws InterruptedException { | |
driver.get("http://only-testing-blog.blogspot.in/2014/05/login.html"); | |
// Download Text File | |
driver.findElement(By.xpath("//a[contains(.,'Download Text File')]")).click(); | |
Thread.sleep(5000);// To wait till file gets downloaded. | |
// Download PDF File | |
driver.findElement(By.xpath("//a[contains(.,'Download PDF File')]")).click(); | |
Thread.sleep(5000); | |
// Download CSV File | |
driver.findElement(By.xpath("//a[contains(.,'Download CSV File')]")).click(); | |
Thread.sleep(5000); | |
// Download Excel File | |
driver.findElement(By.xpath("//a[contains(.,'Download Excel File')]")).click(); | |
Thread.sleep(5000); | |
// Download Doc File | |
driver.findElement(By.xpath("//a[contains(.,'Download Doc File')]")).click(); | |
Thread.sleep(5000); | |
} |