In this tutorials, we are going to learn how to handle SSL certificate errors in selenium.
SSL (Secure Socket Layer) certificate:
An SSL certificate creates a secure channel through which information including usernames, passwords, credit card numbers and more can pass safely. SSL Certificates validate the website’s identity, and encrypt the information visitors send to, or receive from, your site. This keeps hackers from spying on any exchange between you and your visitors.
Benefits of SSL Certificates:
1 Kick out the Hackers
2 Boosts Ranking & Increase Brand Value:
Website gets better ranking in google if it is ssl certificate is valid.
3 Secure Payments to Experience Safe Shopping
4 Build Trust with Extended Authentication
5 Strongest Encryption to Secure Information:
All kinds of information transferred over an SSL connection is encrypted and there is no way an interceptor could decipher your information. Encryption algorithms like RSA, DSA, and ECC are currently being used by most certificate authorities.
How to handle untrusted or insecure SSL certificates in chrome browser:
Method 1:
1 2 3 4 5 6 7 8 9 10 |
// Set desired capabilities for chrome DesiredCapabilities capabilities=DesiredCapabilities.chrome(); capabilities.acceptInsecureCerts(); // pass capabilities to chrome options ChromeOptions co= new ChromeOptions(); co.merge(capabilities); System.setProperty("webdriver.chrome.driver", "give chrome driver path here"); WebDriver driver=new ChromeDriver(co); |
Method 2:
1 2 3 4 5 6 7 8 9 10 |
// Set desired capabilities for chrome DesiredCapabilities capabilities=DesiredCapabilities.chrome(); capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); // pass capabilities to chrome options ChromeOptions co= new ChromeOptions(); co.merge(capabilities); System.setProperty("webdriver.chrome.driver", "give chrome driver path here"); WebDriver driver=new ChromeDriver(co); |
How to handle untrusted or insecure SSL certificates in firefox browser:
1 2 3 4 5 6 7 8 9 |
// Create firefox profile FirefoxProfile profile=new FirefoxProfile(); // Set accept untrusted certificates as true profile.setAcceptUntrustedCertificates(true); // Code to open firefox browser having above profile WebDriver driver=new FirefoxDriver(profile); driver.get("url of the browser"); |
How to handle untrusted or insecure SSL certificate in IE browser:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// *** Handling ssl untrusted ssl certificate in IE browser *** // DesiredCapabilities class object creation DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); // Setting ACCEPT_SSL_CERTS variable to true capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); // Set the Internet Explorer driver path System.setProperty("webdriver.ie.driver","give IE driver path"); // Inject capability to browser WebDriver driver=newInternetExplorerDriver(capabilities); |
Great article on SSL certificate handling.
Please share your selenium and/or java articles @techygeeks99@gmail.com
Good tutorial on SSL certificate. Keep more articles posted.
Thank you for your support Abhishek. Surely we will publish more articles.