When a site has an untrusted or self-signed SSL certificate, browsers show a security warning. Configure the browser to accept these automatically.
Chrome (Selenium 4 — recommended):
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(options);
Firefox (Selenium 4 — recommended):
FirefoxOptions options = new FirefoxOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(options);
Firefox using FirefoxProfile (older approach):
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
WebDriver driver = new FirefoxDriver(profile);
IE using DesiredCapabilities (legacy):
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(capabilities);
Chrome using DesiredCapabilities (legacy):
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome();
handlSSLErr.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new ChromeDriver(handlSSLErr);
Best Practice: Always use browser-specific Options classes (
ChromeOptions,FirefoxOptions) in Selenium 4+ instead of the deprecatedDesiredCapabilities.
