selenium(webdriver)--不同浏览器处理SSL Certificate Error的方法

在看selenium相关文档时,看到了selenium对不同浏览器处理SSL Certificate Error的方法。
因为还没遇到,所以暂时没试,只是记录下来了。

Firefox

  1. 创建一个新的profile,命名为certificateIssue
    (创建方法参照:http://blog.csdn.net/qiyueqinglian/article/details/43053531)
  2. 用刚才创建的profile打开ffx浏览器
  3. 访问报SSL certificate error的URL,通过点击 I Understnad the Risks -> Add Exception button,引进证书,这样就不报错了.
  4. 在代码里配置通过刚才创建的profile打开ffx
    代码如下
ProfilesIni firProfiles = new ProfilesIni();
FirefoxProfile wbdrverprofile = firProfiles.getProfile("certificateIssue");
//在文章的开始我也说了,代码没做实验,这里有个疑问点。是不是设置了下面两行,其实就不用手动创建profile,并认证,然后手动引进证书。等遇到了这类网址再做实验吧。
wbdrverprofile.setAcceptUntrustedCertificates(true); 
wbdrverprofile.setAssumeUntrustedCertificateIssuer(false);
WebDriver Driver = new FirefoxDriver(wbdrverprofile); 
Driver.get("site URL where certificate error");

Chrome

//Set chrome browser's capabilities to to accept SSL certificate on runtime.
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver_win32\\chromedriver.exe");

WebDriver driver = new ChromeDriver(capability);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

//Enter the URL of site where you facing SSL error.
driver.get("Enter site URL");

IE

IE需要通过js来解决。在你遇到证书错误的页面点击F12,就会看到继续访问该页面的ID是”overridelink”。
点击这个就可以继续访问了。
这里写图片描述

// Set path of IEDriverServer.exe
 System.setProperty("webdriver.ie.driver", "D://IEDriverServer.exe");
  WebDriver driver = new InternetExplorerDriver();
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  driver.get("URL of SSL error site");

  //To click on "Continue to this website (not recommended)." link to load original website.
  driver.navigate().to("javascript:document.getElementById('overridelink').click()");
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值