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



TAG: firefox

 

评分:0

我来说两句

日历

« 2024-04-21  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 9052
  • 日志数: 3
  • 建立时间: 2015-09-06
  • 更新时间: 2016-04-12

RSS订阅

Open Toolbar