http://www.cnblogs.com/puresoul/p/4251536.html

一、启动firefox浏览器(不需要下载驱动,原生支持)
1.firefox安装在默认路径下:

//启动默认安装路径下的ffpublic void StartFireFoxByDefault(){System.out.println("start firefox browser...");WebDriver driver = new FirefoxDriver();//直接new一个FirefoxDriver即可Navigation navigation = driver.navigate();navigation.to("http://www.baidu.com/");System.out.println("start firefox browser succeed...");        }

2.firefox未安装在默认路径下:

public static void StartFireFoxNotByDefault(){System.out.println("start firefox browser...");System.setProperty("webdriver.firefox.bin",     "D:/Program Files/Mozilla Firefox/firefox.exe");  //指定firefox的安装路径WebDriver driver = new FirefoxDriver();Navigation navigation = driver.navigate();navigation.to("http://www.baidu.com/");System.out.println("start firefox browser succeed...");        }

3.启动firefox时加载插件:
首先,要知道我们为什么需要加载插件?原因是webdriver在启动浏览器时,启动的一个干净的没有任务、插件及cookies信息的浏览器(即使你本机的firefox安装了某些插件,webdriver启动firefox也是没有这些插件的),但是有可能被测系统本身需要插件或者需要调试等等,此时可以用如下方法在启动firefox时加载插件,下面示例加载firebug插件:

public static void StartFireFoxLoadPlugin(){System.out.println("start firefox browser...");System.setProperty("webdriver.firefox.bin", "D:/Program Files/Mozilla Firefox/firefox.exe");File file = new File("files/firebug-2.0.7-fx.xpi");FirefoxProfile profile = new FirefoxProfile();try {profile.addExtension(file);} catch (IOException e) {e.printStackTrace();}profile.setPreference("extensions.firebug.currentVersion", "2.0.7");//active firebug extensionsprofile.setPreference("extensions.firebug.allPagesActivation", "on");    WebDriver driver = new FirefoxDriver(profile);driver.get("http://www.baidu.com");System.out.println("start firefox browser succeed...");    }

4.启动firefox时设置profile:
面提到过webdriver启动firefox时是启动一个完全新的浏览器,我们除了可以使用上面提到的方法定制插件,webdriver还可以对profile进行定制(在firefox地址栏中输入about:config,可以查看firefox的参数),下面设置代理和默认下载路径:

public static void StartFireFoxByProxy(){String proxyIp = "10.17.171.11";int proxyPort = 8080;System.out.println("start firefox browser...");System.setProperty("webdriver.firefox.bin", "D:/Program Files/Mozilla Firefox/firefox.exe");FirefoxProfile profile = new FirefoxProfile();//设置代理参数profile.setPreference("network.proxy.type", 1);profile.setPreference("network.proxy.http", proxyIp);profile.setPreference("network.proxy.http_port", proxyPort);//设置默认下载路径profile.setPreference("browser.download.folderList", 2);profile.setPreference("browser.download.dir", "D:\\");WebDriver driver = new FirefoxDriver(profile);driver.get("http://www.baidu.com");System.out.println("start firefox browser succeed...");    }

5.启动本机器的firefox配置:

public static void StartLocalFirefox(){System.out.println("start firefox browser...");System.setProperty("webdriver.firefox.bin", "D:/Program Files/Mozilla Firefox/firefox.exe");ProfilesIni pi = new ProfilesIni();FirefoxProfile profile = pi.getProfile("default");WebDriver driver = new FirefoxDriver(profile);driver.get("http://www.baidu.com/");System.out.println("start firefox browser succeed...");    }

6.如果在机器B上要启动机器A上的firefox配置,可以先导出A的配置,然后加载:

1、将A机器上的Profiles文件夹”C:\Users\cloudchen\AppData\Local\Mozilla\Firefox\Profiles”给拷贝出来到某个目录

public static void StartFireFoxByOtherConfig(){System.out.println("start firefox browser...");System.setProperty("webdriver.firefox.bin", "D:/Program Files/Mozilla Firefox/firefox.exe");        File file = new File("files\\lg6mie1i.default");        //profiles文件目录,这里我是放在工程目录下的files文件夹下FirefoxProfile profile = new FirefoxProfile(file);    WebDriver driver = new FirefoxDriver(profile);driver.get("http://www.baidu.com");        System.out.println("start firefox browser succeed...");    }

PS:如果插件或其它东东未加载成功,可以检查下profile文件夹下是否包含插件信息。

二、一个项目中用到的例子

browserName="Firefox";File fileForDownload = new File(FunctionUtil.DOWNLOAD_DIR);String desiredFilePathForDownload = fileForDownload.getAbsolutePath();// Define using which FirefoxFile file = new File("./lib/Mozilla Firefox/firefox.exe");System.setProperty("webdriver.firefox.bin", file.getAbsolutePath());// Due to in VM, the Portal only can work with the proxy type:// AUTODETECT,// In GDC, the AUTODETECT type of porxy cannot work, So set proxy// for these two kinds of proxy here.// Get the Host NameString hostName = System.getenv().get("COMPUTERNAME").trim();FirefoxProfile ff = new FirefoxProfile();if (hostName.equalsIgnoreCase("ARWJMETP01") || hostName.equalsIgnoreCase("arwotmmt01")) {// Set proxy type as: AutoDetectff.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal());}ff.setPreference("browser.download.dir", desiredFilePathForDownload);ff.setPreference("browser.download.folderList", 2);ff.setPreference("browser.download.manager.showWhenStarting", false);ff.setPreference("browser.helperApps.alwaysAsk.force", false);ff.setPreference("browser.helperApps.neverAsk.saveToDisk","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");ff.setPreference("browser.download.panel.shown", false);driver_Original = new FirefoxDriver(ff);

PS: 哪里能下载更早版本的Firefox:
http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/

Firefox 如何查看版本:目录栏右键–menu bar—help–About Firefox

selenium2读书笔记(四)启动Firefox设置profile加载插件相关推荐

  1. webdriver启动浏览器、设置profile加载插件步骤详解

    本文主要记录下在使用selenium2/webdriver时启动各种浏览器的方法.以及如何加载插件.定制浏览器信息(设置profile)等 环境搭建可参考我的另一篇文章:http://www.cnbl ...

  2. selenium中启动chrome浏览器时加载插件

    使用selenium启动的chrome浏览器,一般是干净的浏览器,如果需要使用某个插件,那么启动浏览器时,就需要加载插件, 代码如下: import java.io.File; import org. ...

  3. java 启动程序设置classpath/加载jar、类的方式

    目录 前言 java 类加载器与路径 设置 bootclasspath 设置 Extensions JAR files 设置 classpath jar -jar 方式启动时,设置classpath ...

  4. 3d游戏设计读书笔记四

    3d游戏设计读书笔记四 一.基本操作演练[建议做] 下载 Fantasy Skybox FREE, 构建自己的游戏场景 a. 在AssetStore中搜索Fantasy Skybox FREE并下载. ...

  5. 《关键对话——注意观察,如何判断对话氛围是否安全》读书笔记(四)

    <关键对话--注意观察,如何判断对话氛围是否安全>读书笔记(四) 在对话过程中,既要关注对话内容(即讨论的主题),也要观察对话气氛(即参与者的反应).越早意识到你和对方退出了对话机制,就越 ...

  6. 《FPGA并行编程》读书笔记专栏启动说明

    <FPGA并行编程>读书笔记专栏启动说明 1. <FPGA并行编程>内容简介 2. 专栏内容简介 3. 开启专栏目的 4. 专栏内容安排 5. 专栏时间安排 6. 相关资料下载 ...

  7. 《编程之美》读书笔记(四): 卖书折扣问题的贪心解法

    <编程之美>读书笔记(四):卖书折扣问题的贪心解法 每次看完<编程之美>中的问题,想要亲自演算一下或深入思考的时候,都觉得时间过得很快,动辄一两个小时,如果再把代码敲一遍的话, ...

  8. 11月3日云栖精选夜读:《maven实战》读书笔记2——maven安装(windows和eclipse插件)...

    前言 由于我的工作中开发环境就是windows,IDE是eclipse,因此安装也只涉及和记录这两部分,在看书和动手的过程也就直接跳过其他部分. 笔记 windows中maven的安装 安装条件 ma ...

  9. 从设置、加载、启动看Xilinx FPGA配置流程

    尽管FPGA的配置模式各不相同,但整个配置过程中FPGA的工作流程是一致的,分为三个部分:设置.加载.启动. 本文引用地址: http://www.21ic.com/embed/hardware/pr ...

最新文章

  1. java安卓开发工具_推荐几个非常实用的Android开发工具
  2. Visual C++ 2011-8-15
  3. Gesture Based TableView
  4. nginx中的rewrite用法及实例
  5. VTK:隐式函数之BooleanOperationImplicitFunctions
  6. 制作oracle11g yum源,利用安装盘简单制作yum源
  7. JScript中正则表达函数的说明与应用
  8. HelloDjango 第 04 篇:Django 迁移、操作数据库
  9. oracle Expdp带条件,Oracle 11g expdp中query参数的使用
  10. 转:SQL进阶之变量、事务、存储过程与触发器
  11. 《我也能做CTO之程序员职业规划》之十三:用凸透镜选择技术
  12. Python安装时报缺少DLL的解决办法
  13. LINUX编译sofia-sip
  14. 联邦学习-安全树模型 SecureBoost之终章
  15. 台式计算机 cpu型号大全,电脑cpu的型号有哪些?
  16. Docker 挂载Volume数据卷
  17. DoubanFm之设计模式(一)
  18. python矩阵点乘和叉乘_NumPy点积:取向量积的乘积(而不是求和)
  19. 基于推荐算法的电影系统——总体设计(2)
  20. 关于5G手机,你想知道的都在这里了-千氪

热门文章

  1. 如何对.xlsx另存为.csv文件时,设置为分号分割
  2. 重心座标插值(Barycentric Interpolation)
  3. 多多客商业版周更新:插件市场全面升级为应用商店
  4. POS终端“密事”之签到
  5. MEF入门之不求甚解,但力求简单能讲明白(五)
  6. arduino——提升ADC采样速度
  7. Unity刀光的实现
  8. 站长工具SEO查询软件公测版
  9. 鲸鱼优化算法(WOA)(学习)
  10. 天数最少的年份_为何每年二月天数最少且每月有长有短?只因凯撒大帝一句话...