selenium webdriver - download Text File with Firefox

103 views
Skip to first unread message

patrick...@neolians.com

unread,
Mar 29, 2019, 6:16:38 AM3/29/19
to Selenium Users
Hi All,

my goal is to download a file and check if the file is correct.

If the file is a Pdf, csv, .... the process is gooing well. I'm using a firefox profile (see below)

but when the file is a text file, Firefox open it but it doesnot download it. Even if I want to use the driver.getPageSource() in order to get the file content, I get an html file and not the text file such as

does some one has a solution in order to download a text file using webdriver on Firefox?


the file content using PageSource:
<html><head><link rel="alternate stylesheet" type="text/css" href="resource://content-accessible/plaintext.css" title="Retour à la ligne automatique"></head><body><pre>My File Content
</pre></body></html>

My Firefox profile
   public static FirefoxProfile FirefoxDriverProfile() {
String mimeTypes = "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml,text/rtf,application/octet-stream,text/csv,application/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.spreadsheetml.sheet,application/octet-stream,multipart/x-zip,application/zip,application/zip-compressed,application/x-zip-compressed";
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", Driver.defaultDownloadDirectoryPath.getAbsolutePath());
profile.setPreference("browser.helperApps.neverAsk.openFile", mimeTypes);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", mimeTypes);
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.disable_full_page_plugin_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml");
profile.setPreference("browser.download.useToolkitUI", true);
profile.setPreference("reader.parse-on-load.enabled", false);
profile.setPreference("gecko.handlerService.schemes.txt.0.name", "TextPa");
// Set this to true to disable the pdf opening
profile.setPreference("pdfjs.disabled", true);
return profile;
}

Mark Collin

unread,
Mar 29, 2019, 6:18:56 AM3/29/19
to Selenium Users

PATRICK ALBARET

unread,
Mar 30, 2019, 12:20:13 AM3/30/19
to seleniu...@googlegroups.com
Thanks for the idea.

unfortunatly my application is a JS application with React;
And I don't know how to get the Url as it is generated thru some Js events.
--

Patrick Albaret



Le ven. 29 mars 2019 à 11:19, Mark Collin <fyre...@gmail.com> a écrit :
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0ddf5029-29cf-4839-a410-7beb7dc8afed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Collin

unread,
Apr 3, 2019, 9:47:38 AM4/3/19
to Selenium Users
I would suggest talking with your developers, it must be generating a URL at some point to enable a download.  You should be able to use some dev knowledge and the JavascriptExecutor to obtain the correct URL.
Reply all
Reply to author
Forward
0 new messages