Selenium 设定firefox的启动路径

http://nickelen.iteye.com/blog/1397449

# 火狐启动路径
如果安装了多个Firefox版本,若在创建FirefoxDriver时不指定路径,则启动安装在默认路径下的Firefox浏览器,C:\Program Files\Mozilla Firefox\firefox.exe

Java代码 复制代码  收藏代码
  1. WebDriver webDriver = new FirefoxDriver();  
WebDriver webDriver = new FirefoxDriver();



指定路径通过设定系统属性来实现:

Java代码 复制代码  收藏代码
  1. System.setProperty("webdriver.firefox.bin""C:\\Program Files\\Mozilla Firefox\\firefox.exe");   
  2. WebDriver webDriver = new FirefoxDriver();  
System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver webDriver = new FirefoxDriver();



此时启动为该特定路径下的火狐浏览器实例。

# FirefoxProfile的设定
若使用不带参数的构造方法:new FirefoxDriver(),则会在该路径下生成类似的匿名Profile(Win7):
C:\Users\XXXX\AppData\Local\Temp\anonymous5266162376255423678webdriver-profile
该Profile是从火狐浏览器的默认Profile拷贝而来,火狐浏览器的默认Profile存放在:
C:\Users\daniel.chen\AppData\Roaming\Mozilla\Firefox\Profiles\XXXX.default
若需要使用特定Profile启动,应该使用FirefoxDriver(FirefoxProfile profile)的构造方法,例如:

Java代码 复制代码  收藏代码
  1. FirefoxProfile profile = new FirefoxProfile(new File("D:\\daniel\\FirefoxProfile\\"));   
  2. WebDriver webDriver = new FirefoxDriver(profile);  
FirefoxProfile profile = new FirefoxProfile(new File("D:\\daniel\\FirefoxProfile\\"));
WebDriver webDriver = new FirefoxDriver(profile);



另,创建新的Profile可以在Run中输入 firefox.exe -p 在打开的Profile Manager中管理profile,详情可参考:http://support.mozilla.org/zh-CN/kb/%E7%AE%A1%E7%90%86%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值