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:
- Initialize Driver Options like
ChromeOptions options = new ChromeOptions();
for chrome - Then set the
options.setAcceptInsecureCerts(true)
; - 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);