Auto download is not working in firefox

好久不见. 提交于 2019-12-13 04:25:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!