Syntax error How to take care of SSL certificate issues in chrome browser in Selenium?

How to take care of SSL certificate issues in chrome browser in Selenium?



We can face SSL certificate issue because of the reasons listed below −

  • While the website was developed, its SSL certificate was not proper.

  • The site may have a self-signed certificate.

  • SSL not configured properly at the server level.

Example

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SSLCert {
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      //Desired capabilities for general chrome profile
      DesiredCapabilities c=DesiredCapabilities.chrome();
      c.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
      c.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
      //ChromeOptions for local browser
      ChromeOptions ch= new ChromeOptions();
      ch.merge(c);
      System.setProperty("webdriver.chrome.driver",       "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      WebDriver driver=new ChromeDriver(ch);
   }
}
Updated on: 2020-06-11T12:01:15+05:30

644 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements