</>

Technology

Selenium

Difficulty

Intermediate

Interview Question

How do you handle SSL certificate errors in Selenium?

Answer

Handling SSL Certificate Errors in Selenium

SSL errors appear when sites use self-signed, expired, or untrusted certificates — common in staging/test environments. Selenium provides browser-specific settings to bypass them.

Chrome — ChromeOptions

Java
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true); // accept any SSL cert

WebDriver driver = new ChromeDriver(options);
driver.get("https://self-signed.badssl.com/"); // no SSL warning

Firefox — FirefoxOptions

Java
FirefoxOptions options = new FirefoxOptions();
options.setAcceptInsecureCerts(true);

WebDriver driver = new FirefoxDriver(options);

Edge — EdgeOptions

Java
EdgeOptions options = new EdgeOptions();
options.setAcceptInsecureCerts(true);

WebDriver driver = new EdgeDriver(options);

RemoteWebDriver (Selenium Grid)

Java
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);

WebDriver driver = new RemoteWebDriver(
    new URL("http://localhost:4444/wd/hub"), options
);

Chrome Additional Flags for Strict Environments

Java
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
options.addArguments("--ignore-certificate-errors");
options.addArguments("--allow-insecure-localhost");
options.addArguments("--disable-web-security");

Handle "Your connection is not private" Page

If the warning page does appear (e.g., when flag doesn''t work in some configs):

Java
driver.get("https://problematic-site.com");

// Check if on warning page
if (driver.getTitle().contains("Privacy error") ||
    driver.getPageSource().contains("NET::ERR_CERT")) {

    // Click "Advanced" → "Proceed" (Chrome-specific element IDs)
    driver.findElement(By.id("details-button")).click();
    driver.findElement(By.id("proceed-link")).click();
}

Verify Site Still Works

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

driver.get("https://staging.myapp.com");
Assert.assertEquals(driver.getTitle(), "Dashboard | MyApp");

Important Notes

  • setAcceptInsecureCerts(true) is the W3C standard approach — works across all browsers
  • Only use in test/staging environments — never disable SSL in production automation
  • For API testing with self-signed certs, use trustAllCerts() in Rest Assured separately

Follow AutomateQA

Related Topics