为什么我无法使用Selenium Webdriver通过Firefox下载文件?
我尝试使用该配置文件的设置下载文件在Firefox,但它不工作,你能告诉我什么,我做错了,我使用的代码被发布这条线为什么我无法使用Selenium Webdriver通过Firefox下载文件?
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");
硒下面创建一个新的Firefox每次运行的配置文件。您将需要为硒创建一个firefox配置文件并让您的硒脚本使用它。如果你在这个配置文件上设置自动下载,那么它应该工作得很好!
看到这里 http://girliemangalo.wordpress.com/2009/02/05/creating-firefox-profile-for-your-selenium-rc-tests/
我只做到了这一点对于Java,但我想的方法是相似的。
编辑 Java代码中指定配置是:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
来源:
它每次创建一个新的空白配置文件,不是?唯一可以让我记住我的偏好的方法是通过预定义的配置文件。 – confusified 2013-04-11 10:08:05
花费几天的时间,阅读大量的可能性之后,这个工作对我来说如此我与你分享,我希望它可以是有用的: 我只是这样设置webdriver firefox个人资料:
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream doc xls pdf txt");
该解决方案允许我避免显示firefox下载弹出窗口,并且可以使用selenium webdriver自动下载XLS文件。
那么它不起作用? – Arran 2013-02-18 15:51:42
它不会自动下载文件,我仍然在获取文件下载窗口 – 2013-02-18 15:53:28
作为临时的解决方法,我可以使用AutoIT脚本。 – Hemanth 2013-02-19 06:16:26