为什么我不能下载使用硒的webdriver通过Firefox的文件? [英] Why can't I download a file via Firefox using Selenium Webdriver?
问题描述
我想使用配置文件设置下载文件,在Firefox,但它不工作,你能告诉我什么,我做错了,我现在用的代码被张贴此行
$ B $以下b
无功配置=新FirefoxProfile {EnableNativeEvents =真};
profile.SetPreference(browser.download.folderList,2);
profile.SetPreference(browser.download.manager.showWhenStarting,FALSE);
profile.SetPreference(browser.download.dir,文件夹名);
profile.SetPreference(browser.download.downloadDir,文件夹名);
profile.SetPreference(browser.download.defaultFolder,文件夹名);
profile.SetPreference(browser.helperApps.neverAsk.saveToDisk,图像/ JPEG,应用/ vnd.oasis.opendocument.text,应用/ vnd.oasis.opendocument.spreadsheet,+
应用程序/ vnd.oasis.opendocument.presentation,应用/ vnd.oasis.opendocument.graphics,+
应用程序/ vnd.ms - Excel中,应用程序/ vnd.openxmlformats-officedocument.spreadsheetml.sheet,+
应用程序/ vnd.ms - PowerPoint中,应用程序/ vnd.openxmlformats-officedocument.presentationml.presentation,+
应用程序/ vnd.openxmlformats-officedocument.wordprocessingml.document,应用/ vnd.mozilla.xul + XML+
应用程序/ vnd.google-earth.kml + XML);
花费几天的时间,阅读大量的可能性后,这个工作对我来说,所以我与你分享,我希望它是有用的:
我刚才设置的webdriver的Firefox的配置是这样的:
firefoxProfile.setPreference(browser.helperApps.neverAsk.saveToDisk,应用程序/八位字节流DOC XLS TXT PDF);
这解决方案使我避免了Firefox下载弹出窗口显示,我可以自动下载XLS文件使用硒的webdriver。
I trying to download file in firefox using the profile setting but it does not work can you tell me what i am doing wrong and the code i am using is posted below this line
var profile = new FirefoxProfile { EnableNativeEvents = true };
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.manager.showWhenStarting", false);
profile.SetPreference("browser.download.dir", folderName);
profile.SetPreference("browser.download.downloadDir", folderName);
profile.SetPreference("browser.download.defaultFolder", folderName);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "image/jpeg,application/vnd.oasis.opendocument.text,application/vnd.oasis.opendocument.spreadsheet," +
"application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.graphics," +
"application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet," +
"application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation," +
"application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.mozilla.xul+xml," +
"application/vnd.google-earth.kml+xml");
After spending days trying, and reading lots of possibilities, this one worked for me so I'm sharing with you and I hope it can be useful: I just set the webdriver firefox profile this way:
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream doc xls pdf txt");
This solution allowed me to avoid the firefox download popup to be displayed, and I could download automatically XLS files using selenium webdriver.
这篇关于为什么我不能下载使用硒的webdriver通过Firefox的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!