首页 > 其他分享 >selenium webdriver三种浏览器如何处理不受信任的证书

selenium webdriver三种浏览器如何处理不受信任的证书

时间:2022-12-18 23:31:35浏览次数:63  
标签:webdriver 浏览器 certificate selenium driver SSL DesiredCapabilities true browser

Hello, Welcome to ​​Selenium tutorial​​ in this post we will see how to Handle Untrusted Certificate Selenium.

 

  • What is Untrusted SSL certificate? Whenever We try to access HTTPS website or application so many time you will face  untrusted SSL certificate issue. This issue comes in all browser like ​​IE​​​,​​Chrome​​​,Safari, ​​Firefox​​ etc.

selenium webdriver三种浏览器如何处理不受信任的证书_Selenium

2-       Why we get this certificate issues often?

 

 

This certificates some in multiple conditions and we should know all of them so that we can rectify them easily.

1- Each secure site has Certificate so its certificate is not valid up-to-date.

2– Certificate has been expired on date

3– Certificate is only valid for (site name) 

4- The certificate is not trusted because the issuer certificate is unknown due to many reasons.

 

Handle Untrusted Certificate Selenium

Step 1-We have to create FirefoxProfile in Selenium.

Step 2- We have some predefined method in Selenium called setAcceptUntrustedCertificates() which accept Boolean values(true/false)- so we will make it true.

Step 3-Open Firefox browser with the above-created profile.

 

I have published video on the same.

 

 

Handle untrusted certificate in Firefox

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class SSLCertificate {

public static void main(String[] args) {

//It create firefox profile
FirefoxProfile profile=new FirefoxProfile();

// This will set the true value
profile.setAcceptUntrustedCertificates(true);

// This will open firefox browser using above created profile
WebDriver driver=new FirefoxDriver(profile);

driver.get("pass the url as per your requirement");


}

}

 

 

 

 

 

Since Firefox comes default browser in Selenium so for other browsers like Chrome, IE, Safari we have to use below technique.

Handle untrusted certificate in Chrome

// Create object of DesiredCapabilities class
DesiredCapabilities cap=DesiredCapabilities.chrome();

// Set ACCEPT_SSL_CERTS variable to true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path
System.setProperty("webdriver.chrome.driver","Chrome driver path");

// Open browser with capability
WebDriver driver=new ChromeDriver(cap);

 

 

 


 

Handle untrusted certificate in IE

 

selenium webdriver三种浏览器如何处理不受信任的证书_SSL_02

selenium webdriver三种浏览器如何处理不受信任的证书_SSL_03

// Create object of DesiredCapabilities class

DesiredCapabilities cap=DesiredCapabilities.internetExplorer();

// Set ACCEPT_SSL_CERTS variable to true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path
System.setProperty("webdriver.ie.driver","IE driver path");

// Open browser with capability
WebDriver driver=newInternetExplorerDriver(cap);

View Code

 

 


 

  Handle untrusted certificate in Safari

selenium webdriver三种浏览器如何处理不受信任的证书_SSL_02

selenium webdriver三种浏览器如何处理不受信任的证书_SSL_03

// Create object of DesiredCapabilities class

DesiredCapabilities cap=DesiredCapabilities.safari();

// Set ACCEPT_SSL_CERTS variable to true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path
System.setProperty("webdriver.safari.driver","Safari driver path");

// Open browser with capability
WebDriver driver=new SafariDriver(cap);



I would suggest you add above code in ​​Base Class in Selenium Webdriver​​ so you don’t have to write code again and again.

I have implemented in my office project and found good results.

Thanks for visiting my blog. Please comment below if you finding any issue.

Keep in touch. Have a nice day selenium webdriver三种浏览器如何处理不受信任的证书_Selenium_06



标签:webdriver,浏览器,certificate,selenium,driver,SSL,DesiredCapabilities,true,browser
From: https://blog.51cto.com/u_14181351/5951249

相关文章

  • selenium chrome浏览器启动设置,加载浏览器相关插件设置方法。
     1、加载插件:1publicstaticvoidStartChromeLoadPlugin(){2System.out.println("startfirefoxbrowser...");3System.setProperty("webdriver......
  • 使用浏览器inspect调试app
    使用浏览器inspect调试app在开发混合项目的过程中,常常需要在app环境排查问题,接口可以使用fiddler等工具来抓包,但是js错误就不好抓包了,这里介绍一种调试工具-浏览器。1.调......
  • 如何实现chrome谷歌浏览器多开(独立环境 独立cookie)
    由于各种各样的原因,你可能需要在一个电脑登录某个平台,比如一个电脑登录3个公众号,或者3个知乎等等。最简单的方案是,直接安装3个不同的浏览器,比如一个谷歌浏览器,一个火狐浏......
  • 浏览器渲染原理
    看渲染过程先了解几个概念浏览器进程进程:程序的一次执行,它占有一片独有的内存空间,是操作系统执行的基本单元;线程:是进程内的一个独立执行单元,是CPU调度的最小单元;C......
  • 超级好看的 Edge 浏览器新标签页插件:好用、好看、免费浏览器必备
    BdTab新标签页BdTab新标签页扩展是一款免费无广告、简单好用的的高颜值新标签页扩展。BdTab它颜值高、简单好用、支持高度自定义:在登录之后支持云备份,支持快速切换搜索引擎......
  • 超级好看的 Edge 浏览器新标签页插件:好用、好看、免费浏览器必备
    BdTab新标签页BdTab新标签页扩展是一款免费无广告、简单好用的的高颜值新标签页扩展。BdTab它颜值高、简单好用、支持高度自定义:在登录之后支持云备份,支持快速切换搜......
  • Edge浏览器爱上WebVR
    微软此前表示,Edge浏览器将会取代InternetExplorer成为Windows10的默认网页浏览器。近日,微软宣布计划让Edge浏览器支持WebVR功能,允许用户直接在网页里观看VR内容。......
  • Vue的浏览器中的 webStorage
    Vue的浏览器中的 webStorage1:Api介绍/*webStorage存储内容大小一般支持5MB左右(不同浏览器可能还不一样)浏览器端通过Window.sessionStorage和Window.localStorage属性......
  • Selenium21--验证码测试
    验证码简介有些网站需要验证码通过后方可进入网页,目的很简单,就是区分是自然人访问还是计算机程序访问。验证码:简称为captcha一种随机生成的信息(数字、字母、汉字、......
  • 前端知识学习案例-浏览器得工作原理
      ......