Below is the code, I'm using to invoke firefox to download an xlsx file from a website.
from selenium import webdriver
options=webdriver.FirefoxOptions()
dest_dir = "myDir"
print (options.preferences)
#options.set_preference('profile', profile_path)
#options.set_preference("browser.download.useDownloadDir",True)
options.set_preference("browser.download.folderList",2)
options.set_preference("browser.download.dir",dest_dir)
options.set_preference("browser.download.manager.showWhenStarting",False)
options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/xlsx/xls")
print (options.preferences)
driver = webdriver.Firefox(options=options)
Even with those options, every time I invoke firefox, it requests below questions.
EDIT: After changing
options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/xlsx/xls")
to
options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
issue is resolved. So, I was providing the wrong MIME type for an xlsx file. Referred to What is a correct MIME type for .docx, .pptx, etc.? for getting the correct type.
Thanks a lot @cruisepandey and @djmonki for your help
CodePudding user response:
I generally invokes with these many preferences in my project, and they work seamlessly.
Code :
options.set_preference("browser.download.panel.shown", False)
options.set_preference("browser.helperApps.neverAsk.openFile","text/csv,application/vnd.ms-excel")
options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/msword, 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");
options.set_preference("browser.download.manager.showWhenStarting", False);
options.set_preference("browser.download.manager.alertOnEXEOpen", False);
options.set_preference("browser.download.manager.focusWhenStarting", False);
options.set_preference("browser.download.folderList", 2);
options.set_preference("browser.download.useDownloadDir", True);
options.set_preference("browser.helperApps.alwaysAsk.force", False);
options.set_preference("browser.download.manager.alertOnEXEOpen", False);
options.set_preference("browser.download.manager.closeWhenDone", True);
options.set_preference("browser.download.manager.showAlertOnComplete", False);
options.set_preference("browser.download.manager.useWindow", False);
options.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False);
options.set_preference("pdfjs.disabled", True);
options.set_preference("browser.download.dir", "C:\\Users\\userid\\Desktop\\Automation")
CodePudding user response:
After changing
options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/xlsx/xls")
to
options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
issue is resolved. So, I was providing the wrong MIME type for an xlsx file. Referred to What is a correct MIME type for .docx, .pptx, etc.? for getting the correct type.
Thanks a lot @cruisepandey and @djmonki for your help