Untrusted Certificate Handling In Selenium Webdriver

Posted By : Kishor Kumar Singh | 12-Apr-2018

These certificates come in multiple conditions and we should know all of them so that we can rectify them easily   

 

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

II– Certificate has been expired on the date

III– Certificate is only valid for (site name)

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

 

How to Handle Untrusted Certificate Selenium -

 

1. First of all, We have to create Firefox Profile in Selenium.

2. Then We have some pre-defined method in Selenium called setAcceptUntrustedCertificates()

which accept Boolean values(true/false)- so we will make it true.

3. At Last Open Firefox browser with the above-created profile.

 

 

For 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 created profile

WebDriver driver=new FirefoxDriver(profile);

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

}

}

 

For 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);
 

For IE -

 // Create the object of DesiredCapabilities class

DesiredCapabilities cap=DesiredCapabilities.internetExplorer();

https://www.plagscan.com/plagiarism-check/

// 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 the capability

WebDriver driver=newInternetExplorerDriver(cap);
 

For Safari -

// Create the 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);

 

 

 

Related Tags

About Author

Author Image
Kishor Kumar Singh

Kishor Kumar Singh is highly dedicated towards work and he is a great team player. He believes that “No amount of testing can prove a software right, a single test can prove a software wrong".

Request for Proposal

Name is required

Comment is required

Sending message..