问题
Auto download is not working in firefox. Please help me with below code:
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList",2); //Use for the default download directory the last folder specified for a download
profile.setPreference("browser.download.dir", "D:");
profile.setPreference("browser.download.useDownloadDir", true); profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
profile.setPreference( "browser.download.manager.showWhenStarting", false );
profile.setPreference("pdfjs.disabled", true); // disable the built-in PDF viewer
options.setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
回答1:
to be more precise MIME that worked for me for automating download of xlsx file through firefox is "application/octet-stream".
回答2:
For excel try mime:
FirefoxOptions options = new FirefoxOptions();
options.addPreference("browser.download.folderList", 2)
.addPreference("browser.download.dir", downloadPath)
.addPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel,text/xml,application/x-excel,application/x-msexcel,application/xhtml+xml,application/octet-stream,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
WebDriver driver = new FirefoxDriver(options);
How to handle download pop-up in firefox, while downloading excel using Selenium Webdriver
来源:https://stackoverflow.com/questions/51955959/auto-download-is-not-working-in-firefox