</>

Technology

Selenium

Difficulty

Intermediate

Interview Question

How to handle HTTPS website in Selenium? or How to accept the SSL untrusted connection?

Accept SSL certificates in Selenium using browser Options or DesiredCapabilities with ACCEPT_SSL_CERTS capability.

Answer

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):

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

Firefox (Selenium 4 — recommended):

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

Firefox using FirefoxProfile (older approach):

Java
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
WebDriver driver = new FirefoxDriver(profile);

IE using DesiredCapabilities (legacy):

Java
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):

Java
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 deprecated DesiredCapabilities.

Follow AutomateQA

Related Topics