使用Selenium从Firefox下载Excel文件

时间:2017-08-24 14:20:41

标签: selenium

如何使用Selenium从网上下载Excel文件?我尝试使用firefoxprofile.setpreference,但它对我不起作用。

这是我的代码:

FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir",downloadPath);
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
driver firefoxdriver=new firefoxdriver(firefoxProfile) 

我使用的是Windows 7和Firefox 39.0。

仍在执行期间,Firefox会打开一个窗口,询问我是要保存还是打开文件,默认情况下选中“打开”。

这个问题有解决方案吗?

0 个答案:

没有答案
相关问题