How does Selenium Webdriver handle SSL certificate in Firefox?


We can handle SSL certificate in Firefox with the help of the Selenium webdriver by using the FirefoxProfile class. Then setting the parametersetAcceptUntrustedCertificates to true. A SSL is a protocol followed to create a secure connection between the client (browser) and the server.

SSL checks the authenticity of a website and encodes the visitors while they send or get information from the site. Some of the advantages of SSL certificates are −

  • Earns the users trust by increasing the business growth.

  • Provides a secure gateway for online payment by securing the customer data like username, password, and other banking information.

  • Keeps away from hacker threats.

  • Gives a good brand value, for example, Google gives a good ranking for sites having a valid SSL.

SSL certificate websites begin with https:// where we can find a lock icon in green in address bar, provided the connection is secured.

Syntax

FirefoxProfile p=new FirefoxProfile();
p.setAcceptUntrustedCertificates(true);

Example

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class SSLErrorFirefox{
   public static void main(String[] args) {
      //DesiredCapabilities object
      DesiredCapabilities c=DesiredCapabilities.internetExplorer();
      //set FirefoxProfile
      FirefoxProfile p=new FirefoxProfile();
      // configure setAcceptUntrustedCertificates to true
      p.setAcceptUntrustedCertificates(true);
      System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");
      //configure this profile to browser
      WebDriver driver=new FirefoxDriver(p);
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      driver.get("application url to be entered");
   }
}

Updated on: 06-Apr-2021

934 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements