selenium java 设置firefox的默认下载文件路径
上一篇 /
下一篇 2016-04-12 16:09:02
/ 个人分类:selenium
在学习自动化测试的时候,遇到使用firefox中有下载文件时,会一直有一个下载框在,虽然不影响程序正确运行,但是不能验证文件下载功能是否实现。查找资料之后,发现可以这么解决。
下载框形如下图
解决问题的代码如下:
ProfilesIni allprofiles = new ProfilesIni();
//启动平时用的firefox浏览器,可以把上面"WebDriver"替换成"default"
FirefoxProfile profile = allprofiles.getProfile("default");
//browser.download.folderList 设置Firefox的默认 下载 文件夹。0是桌面;1是“我的下载”;2是自定义
profile.setPreference("browser.download.folderList", "2");
profile.setPreference("browser.download.dir", "E:\\selenium");
//使用默认下载路径?总是询问下载位置
profile.setPreference("browser.download.useDownloadDir", true);
//当一个下载开始时显示下载管理器。true为显示,false为不显示,缺省我true
profile.setPreference("browser.download.manager.showWhenStarting",false);
//指定无需确认即可下载的文件格式
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,"
+ " application/vnd.ms-excel, text/csv, application/zip,application/exe");
//把profile作为参数传入
WebDriver driver = new FirefoxDriver(profile);
相关阅读:
- Selenium 2.0的由来及设计架构(四) (zzzmmmkkk, 2013-8-17)
- Firefox系统手机增加三国市场 含ZTE Open手机 (zaza9084, 2013-11-04)
- 险象环生,Firefox OS能否偷得生机? (zaza9084, 2015-3-06)
- Firefox手机登陆非洲 直指低端市场 (zaza9084, 2015-5-11)
- org.openqa.selenium.firefox.NotConnectedException: Unable to connect to... (喵的啦啦, 2015-9-10)
- Exception in thread "main" org.openqa.selenium.WebDriverException (喵的啦啦, 2015-9-14)
- Firefox下安装selenium IDE插件 (Amei8830, 2015-10-09)
- Mozilla正式推iOS版Firefox浏览器 (zaza9084, 2015-11-13)
- selenium实现firefox浏览器的自动下载保存文件 (ewwerpm, 2016-2-13)
- 关于Sublime text3中,Selenium启动Firefox卡顿问题 (wenling2023, 2016-4-08)
收藏
举报
TAG:
firefox