In this tutorial I will explain you how to download txt, pdf, csv, excel and doc file using firefox profile. You can write a selenium script to download file, if you know the MIME type of the file that you wanted to download.
Download File Using Selenium WebDriver
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class Training {
static WebDriver driver;
public static void main(String[] args) throws InterruptedException {
FirefoxProfile firefoxprofile = new FirefoxProfile();
firefoxprofile.setPreference("browser.download.dir", "D:\\download");
firefoxprofile.setPreference("browser.download.folderList", 2);
firefoxprofile
.setPreference(
"browser.helperApps.neverAsk.saveToDisk",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"
+ "application/pdf;"
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document;"
+ "text/plain;" + "text/csv");
firefoxprofile.setPreference(
"browser.download.manager.showWhenStarting", false);
firefoxprofile.setPreference("pdfjs.disabled", true);
driver = new FirefoxDriver(firefoxprofile);
driver.get("reditblog.blogspot.in/2014/12/how-to-download-file-using-selenium.html");
driver.findElement(By.name("text")).click();
Thread.sleep(5000);
driver.findElement(By.name("pdf")).click();
Thread.sleep(5000);
driver.findElement(By.name("CSV")).click();
Thread.sleep(5000);
driver.findElement(By.name("Excel File")).click();
Thread.sleep(5000);
driver.findElement(By.name("Doc")).click();
Thread.sleep(5000);
driver.quit();
}
}




