Reputation: 113
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.helperApps.alwaysAsk.force", False)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.manager.useWindow", False);
fp.set_preference("browser.download.manager.alertOnEXEOpen", False)
fp.set_preference("browser.download.folderList", 2);
fp.set_preference("browser.download.dir", '/home/ubuntu');
fp.set_preference("browser.download.manager.alertOnEXEOpen", False);
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/vnd.ms-excel, application/force-download,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/msword, application/XLS;text/csv, application/XLSX;text/csv, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream")
fp.set_preference("browser.download.manager.showWhenStarting", False);
fp.set_preference("browser.download.manager.focusWhenStarting", False);
fp.set_preference("browser.download.useDownloadDir", True);
fp.set_preference("browser.helperApps.alwaysAsk.force", False);
fp.set_preference("browser.download.manager.alertOnEXEOpen", False);
fp.set_preference("browser.download.manager.closeWhenDone", True);
fp.set_preference("browser.download.manager.showAlertOnComplete", False);
fp.set_preference("browser.download.manager.useWindow", False);
fp.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False);
fp.set_preference("pdfjs.disabled", True);
driver = webdriver.Firefox(firefox_profile=fp)
That's my code for saving files using Selenium. It works for other files but not with Excel. As you can see enter code here
, I have included a number of Excel file format but these also didn't work.
Also, does PhantomJs has this capability? I've searched but haven't found anything which confirms this capability for PhantomJs.
Thanks for your assistance.
Upvotes: 2
Views: 1271
Reputation: 113
Thank you for your response.
I tried using text/csv but that also didn't work. What I ended up doing was installing httpFox which monitors network traffic and activities. With httpFox I was able to zoom in on the exact MIME-TYPE which is: fp.set_preference("browser.helperApps.neverAsk.saveToDisk","application/msexcel, text/csv")
I tried several other Excel MIME-TYPES which I found on the internet but none of them worked except for the one I used.
T
Upvotes: 1
Reputation: 353
You can use wildcards in MIME types, this can be used to match all excel files and all other files.
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv, application/*")
File downloads can not be done with PhantomJS: https://github.com/ariya/phantomjs/issues/10052
Upvotes: 0