How to Handle SSL Certificate in Selenium WebDriver


How to Handle SSL Certificate in Selenium WebDriver


In this article, we will learn how to handle an untrusted SSL certificate using selenium webdriver.

But Before that,

What is an Untrusted SSL Certificate?

A lot of time you might have observed whenever we tried to access any web page we face message SSL certificates like below in the case of Chrome.






In the case of IE
Similarly In the case of Firefox


There could be many possible reasons for this message like certificate is expired or certificate does not belong to this web page etc.




To handle this certificate issue in any web browser we need to make use of DesiredCapabilities class and then Set ACCEPT_SSL_CERTS variable equals to true.

Below is the code snapshot to handle this in case of Chrome.



Below is the code snapshot to handle this in case of Internet Explorer



Below is the code snapshot to handle this in case of Safari browser.



To handle this error in case of firefox we first, need to create a Firefox profile and then setAcceptUntrustedCertificates as true.

Below is the code snapshot to handle this in the case of Firefox.






SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
September 12, 2019 at 9:26 PM

Hi, can we acheive this in headless browser.

Reply
avatar
September 13, 2019 at 1:53 PM

Hi vaibhav, yes it will work.You need to add code for headless which is also Avilable in this website

Reply
avatar