How To Handle SSL Certificates in Selenium Webdriver in Chrome?

How to Handle SSL Certificate in Selenium WebDriver

In computing, SSL (Secure Sockets Layer) refers to a standard security protocol that is used to establish an encrypted connection between the server and the client, which is typically a browser.

SSL (Secure Sockets Layer) Certificates provide secure data translation between a server and a client application by utilizing a strong encryption standard or digital signature to protect sensitive information. An SSL certificate or a code signing certificate must be installed on the computer.

Benefits of SSL Certificate

There are numerous advantages to using an SSL certificate, including the following:

  • It is possible to strengthen the trust of users and customers to accelerate the growth of a company’s operations.
  • These certificates aid in the security of online transactions as well as the protection of sensitive consumer information such as credit-card/debit-card data, among other things.
  • The signing certificate is the one that receives the greatest number of downloads and positive feedback from users.
  • SSL-secured websites begin with the prefix HTTPS://, and if the connection has been created securely, you will see a lock icon or a green address bar.

Suppose you want to make a transaction using net banking or if you want to purchase a mobile phone from an e-commerce website such as Flipkart or Amazon, for example.

How Does the SSL Certificate Create a Secure Connection

A browser attempts to establish a connection with a website that has been encrypted with SSL. The browser sends a request to the webserver, asking it to identify itself.

A copy of the server’s SSL certificate is sent to the browser by the server.

Verification of the SSL certificate’s authenticity is performed by the web browser. If this is the case, a message is sent to the server.

The server responds with a digitally signed acknowledgment, which allows the client to begin an SSL encrypted session.

The encrypted data is passed back and forth between the server and the client.

To do so, you must transfer sensitive information such as payment card numbers or login passwords, and this information must be transmitted securely to prevent it from being hacked or intercepted.

  • Enter the following URL:
  • Press the Enter key.
  • In your browser, you will see a green address bar, like shown below:-
  • handling SSL certificate errors in the Selenium web driver
  • What is the process through which an SSL certificate creates a secure connection?
  • handling SSL certificate errors in the Selenium web driver
  • The browser communicates with the server using HTTPS.
  • Now, for the Server to be trusted, it must provide some sort of identification to the Browser. This can be accomplished by sending the browser a copy of the server’s SSL certificate.

Each browser has its list of trusted certificate authorities (CAs). If the certificate root matches one of the CAs on the browser’s trusted CAs list, the browser verifies that the certificate has not expired or been revoked and that the common name is legitimate for the website to which the browser is connecting.

The server and the browser establish an encrypted session if the browser believes that the certificate is authenticated by the server.

Both the server and the browser can transmit encrypted messages.

SSL Certificates Come in a Variety of Forms

The SSL Certificate process is used by both the browser and the server to establish a secure connection. The verification of three different sorts of certifications is required for this connection.

Types of SSL Certificates

  • To begin, you must submit a CSR (Create a Certificate Signing Request) request to the server.
  • The CSR request generates a CSR data file, which is then forwarded to the SSL certificate issuer, also known as the CA (Certificate Authority).
  • The CSR data files are used by the CA to generate an SSL certificate for your server.
  • After you have received your SSL certificate, you must install it on your computer’s server.
  • Additionally, you’ll need to install an intermediate certificate, which will link your SSL certificate to the root certificate of the CA.
  • The three certificates depicted in the image below are the Root Certificate, the Intermediate Certificate, and the Server Certificate.

handling SSL certificate errors in the Selenium web driver

The process by which SSL certificates are validated

Securing a website (SSL) is accomplished through the use of a mix of programs and encryption/decryption routines that are installed on both the webserver computer and the webserver browser.

The information contained in an SSL certificate is summarised here.

The subject of the sentence is the identity of the website’s proprietor.

Validity information is provided in the form of a public and a private key.

The private key and the public key are two cryptographic keys that are inextricably linked to one another (numbers). The only way to decrypt something encrypted with a public key is to use it with a private key.

  • handling SSL certificate errors in the Selenium web driver
  • When a secure connection between the server and the client is not created as a result of the certificate, the following SSL certificate error will be shown.
  • SSL Certificate Errors Come in a Variety of Forms
  • Consider the following scenario: you enter an HTTPS request in your browser and receive a notice such as “This connection is untrusted” or “The site’s security certificate is not trusted,” depending on which browser you are using. If this is the case, the problem is classified as an SSL certificate error.
  • Once this has been accomplished, if the browser is not successful in creating a secure connection with a requested certificate, the browser will issue an “Untrusted Connection” exception as seen below, and prompt the user to take appropriate action.
  • The types of errors you are likely to encounter as a result of a certificate issue in different browsers may look somewhat like this.
  • Firefox – This connection has been identified as unsafe.
  • Google Chrome – This website’s security cannot be relied upon.
  • Internet Explorer (IE) – This website’s security certificate was not trusted by a trustworthy certificate authority when it was presented to the browser (CA)
  • handling SSL certificate errors in the Selenium web driver
  • Learn how to deal with an SSL Certificate Error while using the Selenium Webdriver.
  • If we have built some test scripts and, when executing the script, we are presented with the condition described above as “Untrusted Connection,” how can we manage the exception solely through automated processes?

How SSL certificates are verified

In such a circumstance, we must modify our script in such a way that it will automatically handle the SSL Exception.

The scripts must be adjusted following the type of browser instance that we are now employing. When the desired capabilities enter the scene, this is what happens.

It is necessary to configure the driver instance of Selenium Webdriver using the Desired Capabilities property. A user can configure all driver instances including ChromeDriver, FirefoxDriver, and Internet Explorer by using the Desired Capabilities feature.

As of right now, we do not have a specific URL to use to generate the aforementioned scenario, but I am proposing steps that we may include in our Selenium Script to deal with the “Untrusted Connection” problem described above.