我試圖在使用 Selenium C# 實作匯出質子郵件時自動下載 eml 檔案。根據 MimeMapping.GetMimeMapping,MIME 型別是 message/rfc822。但是,盡管設定了以下首選項,下載檔案的彈出視窗仍然會出現。關于如何在這種特殊情況下避免彈出視窗的任何想法?
opcion.SetPreference("browser.helperApps.neverAsk.saveToDisk", "message/rfc822");
FirefoxOptions opcion = new FirefoxOptions();
opcion.SetPreference("browser.download.folderList", 2);
opcion.SetPreference("browser.download.manager.showWhenStarting", false);
opcion.SetPreference("browser.download.dir", ruta);
opcion.SetPreference("browser.download.useDownloadDir", true);
opcion.SetPreference("browser.download.viewableInternally.enabledTypes", "");
opcion.SetPreference("browser.helperApps.alwaysAsk.force", false);
opcion.SetPreference("browser.helperApps.neverAsk.saveToDisk", "Unknown/Extension missing, text/javascript, application/x-javascript,application/javascript, multipart/x-gzip, application/x-gzip, application/x-gzip, text/css, text/plain, application/x-binary, message/partial, multipart/form-data, multipart/byteranges,RFC-822 data,text/plain,application/pdf,application/eml,gzip,application/javascript,gzip,image/gif,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,application/protonmail.ch, application/protonmail.com,image/pjpeg,application/vnd.semf,application/vnd.semd,application/vnd.sema,message/rfc822,multipart/x-gzip,multipart/eml,application/x-gzip,application/octet-stream,Thunderbird Document,wget url\\sample.eml,application/xml,text/plain,text/xml,image/jpeg,text/eml,test/sample/message.eml,application/blob,text/plain,multipart/mixed,application/pdf,text/plain,application/text,text/xml,application/xml,application/json,application/eml,blob://");
uj5u.com熱心網友回復:
最后在這種情況下要走的路是設定 opcion.SetPreference("browser.download.improvements_to_download_panel", true);
最終的代碼是:
FirefoxOptions opcion = new FirefoxOptions();
opcion.SetPreference("browser.download.folderList", 2);
opcion.SetPreference("browser.download.manager.showWhenStarting", false);
opcion.SetPreference("browser.download.dir", ruta);
opcion.SetPreference("browser.download.improvements_to_download_panel", true);
opcion.SetPreference("browser.download.manager.showWhenStarting", false);
opcion.SetPreference("browser.download.useDownloadDir", true);
opcion.SetPreference("browser.download.viewableInternally.enabledTypes", "");
opcion.SetPreference("browser.helperApps.alwaysAsk.force", false);
opcion.SetPreference("browser.helperApps.neverAsk.saveToDisk", "Thunderbird Document, blob: ,application/vnd.protonmail.v1 json, application/json, json, media-src,blob,message, message/rfc6532,message/partial, message/external-body, message/rfc822, application/octet-stream, text/plain, application/download, application/octet-stream, binary/octet-stream, application/binary, application/x-unknown, texto/html");
opcion.SetPreference("pdfjs.disabled", true);
return opcion;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/382043.html
上一篇:未加載參考導航屬性(物體框架)
