How does Selenium Webdriver handle the SSL certificate in Safari?


Selenium webdriver is capable of handling SSL certificate in the Safari browser. This is done with the help of the DesiredCapabilities class. We shall create an object of this class. Then apply the setCapability method on it and set the value of property CapabilityType.ACCEPT_SSL_CERTS to true.

The SSL is a protocol developed to have a secure connection between the server and the client browser. It verifies the website authenticity before any further communication with it.

Syntax

DesiredCapabilities pc = DesiredCapabilities.safari();
pc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

Example

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.safari.SafariDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SSLErrorSafari{
   public static void main(String[] args) {
      //instance of DesiredCapabilities
      DesiredCapabilities pc = DesiredCapabilities.safari();
      //set capability
      pc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
      //set capability to webdriver
      WebDriver driver=new SafariDriver(pc);
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      driver.get("application url to be entered");
   }
}

Updated on: 08-Apr-2021

287 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements