File Downloading - file is not downloading. | Selenium Forum
M
Posted on 05/01/2016
public class fileDownloading {


public static void main(String[] args) {

FirefoxProfile profile=new FirefoxProfile();
////0 desktop, 1 download folder 2 specified folder
profile.setPreference("browser.download.folderList", 2);
//prevent download Managerwindow are coming
profile.setPreference("browser.download.manager.showWhenStarting", false);
//
profile.setPreference("brower.download.dir", "C:\\temp"); //path of folder where you wnat to download.
//what kind of file should be download automatically on drive, this property explain that
//mine type- any file exe, xls, word, txt etc have there own mine type.
//google- type mine types of files specified here
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv, application/excel,application/x-excel");
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);

//now we want to download file
//so here open firefox with specified profile
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();

}

}

-----------------------
Code is working fine, no error displayed however not downloading file.(i have already created temp folder on C driver )

My observation is, on click on each link when it open download window, on video session bydefault save radio option was selected. however when i am running my code, that time 'Open' radio button is bydefault selected. may be that is an issue.(attached please find screenshot).

If so, then how should i handle this scenario, how do I select radio button from that screen which is window screen.

waiting for your reply..

M
Replied on 05/01/2016

use this link http://stackoverflow.com/questions/34271396/how-to-handle-downloading-xlsx-file-in-firefox-using-webdriver-where-window-pop


and use this code
[code:11w0luti]public static void main(String[] args) {

FirefoxProfile profile = new FirefoxProfile();
// //0 desktop, 1 download folder 2 specified folder
profile.setPreference("browser.download.folderList", 2);
// prevent download Managerwindow are coming
profile.setPreference("browser.download.manager.showWhenStarting",
false);
//
profile.setPreference("brower.download.dir", "C:\\temp"); // path of
// folder
// where you
// wnat to
// download.
// what kind of file should be download automatically on drive, this
// property explain that
// mine type- any file exe, xls, word, txt etc have there own mine type.
// google- type mine types of files specified here
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);

// now we want to download file
// so here open firefox with specified profile
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();

}

[/code:11w0luti]


M
Replied on 08/01/2016

I have writtten the same code. no difference...

eventhrought i used your code, still it is not working. I feel that basic problem here is, open file radio button is by default selected. What do you thing.
If so then how should I handle it.


M
Replied on 08/01/2016

with the code i have given you is working it will download your xlsx and docx files with prompting.