How to Handle SSL Certificates in Selenium WebDriver for Chrome, Firefox, Edge, and Safari Browsers
Handling SSL Certificate for Chrome, Firefox, Safari, and Edge browser
Handling SSL Certificate for Chrome, Firefox, Safari, and Edge browser

This tutorial will guide you through the process of handling SSL Certificates in Selenium WebDriver for different browsers like Chrome, Firefox, Edge, and Safari in a step-by-step manner.

List of SSL Certificates which we need to handle:

  • Expired
  • self-signed
  • untrusted-root
  • revoked

Steps:

  1. Initialize Driver Options like ChromeOptions options = new ChromeOptions();for chrome
  2. Then set theoptions.setAcceptInsecureCerts(true);
  3. While initializing the WebDriver, pass the ChromeOptions

Example

package TestAutomationCentral;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class SSLCertificate {
public static void main(String[] args) {
//TestAutomationCentral.com
System.setProperty("webdriver.chrome.driver", "C:\\temp\\drivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(options);
driver.get("https://expired.badssl.com/");
}
}

Code Snippet

Chrome

ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(options);

Firefox

FirefoxOptions options = new FirefoxOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(options);

Edge

EdgeOptions options = new EdgeOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new EdgeDriver();

Safari

SafariOptions options = new SafariOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new SafariDriver(options);
Share

Leave a Reply