ProfilesIni allprofiles = new" />

selenium设置firefox的默认下载文件路径

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

selenium java 设置firefox的默认下载文件路径

在学习自动化测试的时候,遇到使用firefox中有下载文件时,会一直

有一个下载框在,虽然不影响程序正确运行,但是不能验证文件下载功

能是否实现。查找资料之后,发现可以这么解决。

下载框形如下图

解决问题的代码如下:

1. ProfilesIni allprofiles = new ProfilesIni();

2.

 

3.

//启动平时用的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("eDownloadDir",

true);

//当一个下载开始时显示下载管理器。true为显示,false为不显示,

缺省我true

profile.setPreference("browser.download.manager.showWhenStarting",fals //指定无需确认即可下载的文件格式

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);

相关文档
最新文档