自动下载在Firefox中不起作用。请通过以下代码帮助我:
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);
答案 0 :(得分:0)
对于excel,请尝试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
答案 1 :(得分:0)
更准确地说,对我来说,通过firefox自动下载xlsx文件的MIME是“ application / octet-stream”。