How to download file using chromedriver and give file name | Selenium Forum
M
Posted on 19/11/2015
Hi,
Can you please give me an idea how to download pdf file using chromedriver and letme know how to save that file with specific name(not system default name, application generating null name).
We have application after executing each testcase generate one pdf file(if we click View Information button), by clicking this button new browser tab will be open with pdf file name as null0 name). So I can capture pdf link in string but I want to save this file and name it with testcase name to compare baseline documents.
I have testcase name as string to give the pdf name and url link in one string.
I tried in firefox and chrome but not succeed. (Its not asking to save document, pdf link will generating new tab).

sorry Its long info.. can any one give an idea how to this. Ashish can you please help me when you get chance

Thanks
Sankara

M
Replied on 19/11/2015

use this code for firefox.


[code:1emy3nvd] FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting",
false);
profile.setPreference("browser.download.dir", "C:\\temp");
// profile.setPreference("browser.helperApps.neverAsk.openFile",
// "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,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ");
profile.setPreference(
"browser.helperApps.neverAsk.saveToDisk",
"application/pdf,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,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting",
false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete",
false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("plugin.scan.Acrobat", false);
profile.setPreference("plugin.scan.plid.all", "99.0");
profile.setPreference("pdfjs.disabled", true);

WebDriver driver = new FirefoxDriver(profile);
driver.get("https://go.berniesanders.com/page/-/8.5x11_LitPiece%20(1).pdf");[/code:1emy3nvd]

reference(but its in ruby and not in java):"http://yizeng.me/2014/05/23/download-pdf-files-automatically-in-firefox-using-selenium-webdriver/"


M
Replied on 19/11/2015

Thanks for reply. I need to rename pdf file within this method once it download in local drive with test case name . This very important in this project.
Thanks
Sankara