try this
package com.soapuitutorial.propertie;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class DownloadWithoutPrompt {
// http://stackoverflow.com/questions/34271396/how-to-handle-downloading-xlsx-file-in-firefox-using-webdriver-where-window-pop
public static void main(String[] args) {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting",
false);
profile.setPreference("brower.download.dir", "C:\\temp"); // path of
profile.setPreference(
"browser.helperApps.neverAsk.saveToDisk",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
profile.setPreference("browser.download.manager.showWhenStarting",
false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://qtpselenium.com/test/testdownload.php");
driver.findElement(By.xpath("html/body/a[1]")).click();
driver.findElement(By.xpath("html/body/a[2]")).click();
driver.findElement(By.xpath("html/body/a[4]")).click();
}
}
Its an excel file. The behavior is like this once you click on the download link, it opens a new window and then displays the 'Save as' dialog box.
Sorry cannot share the url here, all I can share is that the download link has got the following HTML:
[code:3q5tzm52]<a target="_blank" href="/athena/bir/download/export/198">Download</a>[/code:3q5tzm52]
It works fine if the html code of the download link is:
[code:3q5tzm52]<a target="_self" href="/athena/bir/download/export/198">Download</a>[/code:3q5tzm52]
use this to get the mime type
add that to the list
[code:135w9pet]Path p1 = Paths
.get("path/to/.csv/file");
String x = Files.probeContentType(p1);
System.out.println(x);[/code:135w9pet]