0

I tried:

setPreference("browser.helperApps.neverAsk.saveToDisk","application/xls;text/csv");  

.

setPreference("browser.helperApps.alwaysAsk.force", false);  

.

profile.set_preference("browser.helperApps.neverAsk.saveToDisk",application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")  

but Firefox always asks if I want to open the file. It works fine for XLS file.

Any ideas?

pnuts
  • 58,317
  • 11
  • 87
  • 139
filip
  • 1
  • deleted my answer because i just realized the mime type is actually `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` which you do have. – ddavison Nov 05 '15 at 20:14
  • thanks, your suggestion actually make sense, I will try to read file using some stream without the clicking, from the url – filip Nov 05 '15 at 20:19
  • that definitely is the best way to go about it. – ddavison Nov 05 '15 at 20:26
  • it would be still interesting to know, why the download does not work for xlsx files. – filip Nov 05 '15 at 22:45

1 Answers1

0

I had a similar issue.

Here's my working browser profile config lines.

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.helperApps.alwaysAsk.force", False);
profile.set_preference("browser.download.dir", 'Desktop')
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

driver = webdriver.Firefox(firefox_profile=profile)

In my setup the browser would normally prompt he user to save or download upon page load. With this setup it just automatically downloads. One thing to keep in mind is how you're creating the spreadsheet. In my case the PHPExcel_IOFactory library is creating it as openxmlformats-officedocument.spreadsheetml.sheet with these lines.

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

PHPExcel_IOFactory::createWriter($new_excel_object, 'Excel2007');

So it's possible the file type you're trying to download doesn't match it's expected type.

Elliot Robert
  • 355
  • 1
  • 4
  • 13