Java+Selenium3方法篇32-处理不安全连接
来源:互联网 发布:如何查看网络ip地址 编辑:程序博客网 时间:2024/06/05 10:25
本篇介绍webdriver处理不信任证书的情况,我们知道,有些网站打开是弹窗,SSL证书不可信任,但是你可以点击高级选项,继续打开不安全的链接。举例来说,大家都应该用过12306网站购票,点击新版购票,是不是会出现如下的界面。
先来看看chrome上如何处理这个,跳过图中这个步骤,直接到买票页面。
package lessons;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.remote.CapabilityType;import org.openqa.selenium.remote.DesiredCapabilities; public class HandPopup { public static void main(String[] args) throws Exception { // 创建DesiredCapabilities类的一个对象实例DesiredCapabilities cap=DesiredCapabilities.chrome(); // 设置变量ACCEPT_SSL_CERTS的值为Truecap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); System.setProperty("webdriver.chrome.driver", ".\\Tools\\chromedriver.exe"); // 打开带capability设置选项的浏览器WebDriver driver=new ChromeDriver(cap);driver.manage().window().maximize();driver.get("https://kyfw.12306.cn/otn");} }然后,我们来看看firefox上如何实现这个过程。
package lessons;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.firefox.FirefoxProfile; public class HandPopup { public static void main(String[] args) throws Exception {System.setProperty("webdriver.gecko.driver", ".\\Tools\\geckodriver.exe"); // 创建 firefox profileFirefoxProfile profile = new FirefoxProfile(); // 把这项值设置为True,就是接受不可信任的证书profile.setAcceptUntrustedCertificates(true); // 打开一个带上门设置好profile的火狐浏览器WebDriver driver = new FirefoxDriver(profile);driver.manage().window().maximize();driver.get("https://kyfw.12306.cn/otn");} }运行发现,chrome的可以实现目的,firefox上却不可以。我也不知道什么鬼东西,只能推到geckodriver.exe的bug,因为之前selenium2.x是可以在火狐上实现这个功能的。
阅读全文
0 0
- Java+Selenium3方法篇32-处理不安全连接
- Java+Selenium3方法篇26-处理Alert弹窗
- Java+Selenium3方法篇34-如何处理日历控件
- Java+Selenium3方法篇37-Robot类处理文件上传
- Java+Selenium3方法篇38-AutoIt工具处理文件上传
- Java+Selenium3方法篇25-isDisplayed方法
- Java+Selenium3方法篇13-findElements举例
- Java+Selenium3方法篇39-Explicit wait
- Java+Selenium3方法篇41-FluentWait
- Java+Selenium3方法篇21-webdriver处理浏览器多窗口切换
- Java+Selenium3方法篇22-利用Javascript处理竖向滚动条
- Java+Selenium3方法篇27-利用JS处理元素高亮显示
- Java+Selenium3方法篇21-webdriver处理浏览器多窗口切换
- Java+Selenium3方法篇2-Timeout接口相关方法介绍
- Java+Selenium3方法篇3-window接口相关方法介绍
- Java+Selenium3方法篇30-Selenium中截图方法-TakeScreenshot
- Java+Selenium3方法篇4-Navigation接口介绍
- Java+Selenium3方法篇5-findElement之By id
- JVM系列3-GC算法 垃圾收集器概述
- JZ2440编译 u-boot
- Another git process semms to be running in this repository, e.g. an editor opened by ‘git commit’. P
- 【GamePlay3D游戏引擎学习笔记】——前言
- JVM系列4-GC log
- Java+Selenium3方法篇32-处理不安全连接
- 命令模式
- python正则表达式re
- JVM系列5-JVM调优
- ubuntu安装lxml类库
- python-PIL
- RestFul API 设计
- [深度学习] RCNNs系列(4)Faster RCNN介绍
- sfd