Learn how to fix SSL certificate error in selenium

This article covers what is an SSL certificate is and how to fix SSL certificate error in selenium.

Selenium makes repetitive test tasks easier by simulating human interactions in the web browser, but there are specific differences in how tests are run through automation.

We may have encountered a case where manually opening a website works fine, but the same action via Selenium WebDriver will result in an error message stating that this connection is not trusted.

Have you ever wondered why this is happening? The answer is simple: if you manually open a URL, the browser will automatically import the required certificates and no error will occur. At the same time, every execution in Selenium WebDriver takes place in a new profile that does not have the SSL(Secure Sockets Layer) certificates, hence the error keeps occurring.

In this article, You will learn everything about SSL certificate and learn how we can deal with SSL certificate in Selenium and take appropriate measures in the event of SSL certificate errors in different browsers.

SSL Certificate error

SSL (Secure Sockets Layer) is a standard security protocol that creates a secure connection between the server and the client (browser). Information sent with an SSL certificate is encrypted and ensures that it is sent to the correct server. It is a website identity validator and helps get rid of hackers.

Steps to Fix SSL certificate error

We can handle the SSL error by using the below code

  • Create ChromeOptions Instance
ChromeOptions SSLhandling = new ChromeOptions();
  • Use the accept insecure certs method with true as a value to accept the untrusted certificate
SSLhandling.setAcceptInsecureCerts(true);
  • Creating an instance of Chrome driver by passing reference of ChromeOptions object
WebDriver driver = new ChromeDriver(SSLhandling);
  •  Launch the application
driver.get("https://www.swingli.com/");
System.out.println("The page title is : " +driver.getTitle());
driver.quit();
Conclusion

This article covered what is SSL and how to fix SSL certificate error in selenium chrome drivers. We hope it resolved your problem of such an issue. Happy Automating

Leave a Reply