51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 30611|回复: 25
打印 上一主题 下一主题

selenium问题是只能打开firefox浏览器,不能访问网址。

[复制链接]
  • TA的每日心情
    郁闷
    2017-1-11 15:48
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    1#
    发表于 2013-12-16 14:50:30 | 显示全部楼层
    在公司里边,需要设置Firefox的代理,才能访问被测试的网站。selenium的代码如下: 将墙面两行的xx改成你们公司的IP地址和端口号即可。

    String proxyIp = "xx.xx.xx.xx";
      int proxyPort = xx;
      FirefoxProfile profile = new FirefoxProfile();
      // 使用代理
      profile.setPreference("network.proxy.type", 1);
      // http协议代理配置
      profile.setPreference("network.proxy.http", proxyIp);  
      profile.setPreference("network.proxy.http_port", proxyPort);
      
      profile.setPreference("network.proxy.ssl", proxyIp);  
      profile.setPreference("network.proxy.ssl_port", proxyPort);
       
      // 所有协议公用一种代理配置,如果单独配置,这项设置为false
      profile.setPreference("network.proxy.share_proxy_settings", true);
       
      // 对于localhost的不用代理,这里必须要配置,否则无法和webdriver通讯
      profile.setPreference("network.proxy.no_proxies_on", "localhost");
       
      // 以代理方式启动firefox
      FirefoxDriver driver  = new FirefoxDriver(profile);
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-5-4 16:34 , Processed in 0.062360 second(s), 21 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表