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

Software TestingAutomation TestingSelenium Web Driver

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);
   }
}
raja
Published on 11-Jun-2020 15:31:15
Advertisements