0 votes
1 view
in Devops and Agile by (14.9k points)

I am using Selenium to launch a browser. How can I deal with the webpages (URLs) that will ask the browser to accept a certificate or not?

In Firefox, I may have a website like that asks me to accept its certificate like this:

Firefox

On the Internet Explorer browser, I may get something like this:

Enter image description here

On Google Chrome:

Google Chrome

I repeat my question: How can I automate the acceptance of a website's certificate when I launch a browser (Internet Explorer, Firefox and Google Chrome) with Selenium (Python programming language)?

1 Answer

0 votes
by (42.1k points)

Handle Untrusted Certificate Selenium

Step 1-We have to create FirefoxProfile in Selenium.

Step 2- We have a 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.

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 another browser like Chrome we have to use the 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);

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

I hope, this helps you handle unauthorized certifications! 

...