Accepting Untrusted SSL certificate in WebDriver for Chrome and Firefox Browser

firefox-certificate-errorSome time we get these SSL errors or notification when we try to execute our scripts, but WebDriver has provided us to give capabilities to the Chrome Driver/Firefox to handle these things

Here I am posting the code that would help you in resolving the SSL error mainly in Chrome Browser

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new ChromeDriver(capability);

Above script will help you in accepting all the SSL certificate and by doing so you would not get any SSL error while executing your code.

In Firefox you need to apply this code

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class acceptSSLCerti {
 public static void main(String[] args) {
 //Class ProfilesIni details
 ProfilesIni allProfiles = new ProfilesIni();
 // Use FirefoxProfile Constructor
 FirefoxProfile myProfile = allProfiles.getProfile("CertificateIssue"); myProfile.setAcceptUntrustedCertificates(true); myProfile.setAssumeUntrustedCertificateIssuer(false);
 WebDriver Driver = new FirefoxDriver(myProfile); Driver.get("http://abodeqa.wordpress.com");
}
}

Hope after using these code you would not face SSL error in your script execution.

23 thoughts on “Accepting Untrusted SSL certificate in WebDriver for Chrome and Firefox Browser

  1. how to work with IEBroser with Webdriver, am able to open the required page but not able to do the actions, pls let me know the solution, am in urgency pls dir

    • use the code of Chrome, but in place of Chrome use IE

      or use directly this code

      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
      _driver = new InternetExplorerDriver(capabilities);

  2. Dear Dwarika,
    I tried “CapabilityType.ACCEPT_SSL_CERTS, true” for IE but it fails. Have you tested this ? Although I found another way
    driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);

  3. Yes, I’ve included and I tested on IE 10. Here is complete program. Chrome and FF works good with its own approach but not IE.

    public class Certificate {

    private static WebDriver driver = null;

    public static void main(String[] args) {

    //ffDriver();
    //chromeDriver();
    ieDriver();
    }

    private static void ffDriver() {

    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile Profile = allProfiles.getProfile(“default”);
    Profile.setAcceptUntrustedCertificates(true);
    Profile.setAssumeUntrustedCertificateIssuer(false);

    driver = new FirefoxDriver();
    driver.get(“https://182.72.191.163/CCMLoadBalance/login.aspx”);

    }

    private static void chromeDriver() {
    DesiredCapabilities capability = DesiredCapabilities.chrome();
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    System.setProperty(“webdriver.chrome.driver”,”E:\Selenium\chromedriver.exe”);
    driver = new ChromeDriver(capability);
    driver.get(“https://182.72.191.163/CCMLoadBalance/login.aspx”);
    }

    private static void ieDriver() {

    //Add this desiredcapabilities when the security level of IE not set to same.
    DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
    caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
    caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    System.setProperty(“webdriver.ie.driver”,”E:\Selenium\IEDriverServer.exe”);
    driver = new InternetExplorerDriver(caps);
    driver.get(“https://182.72.191.163/CCMLoadBalance/login.aspx”);
    //driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);
    }

    }

    • caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true)

      So please keep this line of code away from the capability insertion in IE initialization.
      To work with IE problem go manually to the security and set the Protected mode and then run the code that you have written for the SSL by removing the above line for protected mode.

      Try again and this time it will work.

  4. I tried all you said suggestions before earlier post, but No luck! How ever as I mentioned earlier I found a completely different way to deal with IE 10. Might be capability works for IE 9 only and not 10!

    driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);

    This works fine but I was not happy with this work around jugad! So I was trying in your way of approach through capability. Appreciate your interest in discussion.

    • I am thankful to Shama..for spreading this post to more and more people..Any study material should not be bounded to license this is my perception..

      I will request to more and more people from testing fraternity to spread posts..

  5. Even I am facing the same problem with IE 10 like Mohan. I tried all the workarounds but doesnt work so even i tried with driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);
    But wth no luck. Hoping for some suggestion or else i have try out for some older IE versions.

    Thanks,
    Swatik

  6. Hi,
    Thanks for the useful tips in Selenium.

    I’m facing an issue while running Test scripts in Firefox Browser inside the proxy network.
    Though I have enabled ‘No Proxy’ or ‘Manual Proxy’ from Network Settings but whenever the script invokes Firefox instance, the proxy settings gets changed to ‘Use System Proxy Settings’.

    I want to set the desired proxy from the scripts itself.

    I tried the following code from – http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp
    String PROXY = “localhost:8080″;

    org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
    proxy.setHttpProxy(PROXY)
    .setFtpProxy(PROXY)
    .setSslProxy(PROXY);
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(CapabilityType.PROXY, proxy);
    WebDriver driver = new FirefoxDriver(cap);

    and from : http://stackoverflow.com/questions/14235802/how-to-set-auto-detect-proxy-settings-in-webdriver-selenium-java
    import org.openqa.selenium.Proxy.ProxyType;`

    public static WebDriver dr = null;
    org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
    proxy.setSslProxy(“proxyurl”+”:”+8080);
    proxy.setFtpProxy(“proxy url”+”:”+8080);
    proxy.setSocksUsername(“SSSLL277″);
    proxy.setSocksPassword(“password”);

    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(CapabilityType.PROXY, proxy);
    dr = new FirefoxDriver(dc);

    In first code the setHttpProxy method itself is not recognized; same happened with setSslProxy from second code.

    I’m missing any jar or imports?

    Thanks,
    Razen

    • ProxyServer server = new ProxyServer(8105);
      server.start();
      server.setCaptureHeaders(true);

      server.setCaptureContent(true);
      server.newHar(“test”);
      DesiredCapabilities capabilities = new DesiredCapabilities();
      Proxy proxy = server.seleniumProxy();
      FirefoxProfile profile = new FirefoxProfile();
      profile.setAcceptUntrustedCertificates(true);
      profile.setAssumeUntrustedCertificateIssuer(true);
      profile.setPreference(“network.proxy.http”, “localhost”);
      profile.setPreference(“network.proxy.http_port”, 8105);
      profile.setPreference(“network.proxy.ssl”, “localhost”);
      profile.setPreference(“network.proxy.ssl_port”, 8105);
      profile.setPreference(“network.proxy.type”, 1);
      profile.setPreference(“network.proxy.no_proxies_on”, “”);
      profile.setProxyPreferences(proxy);
      capabilities.setCapability(FirefoxDriver.PROFILE,profile);
      capabilities.setCapability(CapabilityType.PROXY, proxy);
      WebDriver driver = new FirefoxDriver(capabilities);
      driver.get(“http://www.google.com”);
      Har har1 = server.getHar();

      Hope this code would help you

  7. Hi,
    I have certificate problems with firefox (as per your screen-grab). I am new to selenium and creating automated tools, what file extension do I use for your script.

  8. I am trying following code:

    public class FirefoxSSLCertificate {
    public static void main(String[] args) {
    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile myProfile = allProfiles.getProfile(“CertificateIssue”);
    myProfile.setAcceptUntrustedCertificates(true);
    myProfile.setAssumeUntrustedCertificateIssuer(false);
    WebDriver driver = new FirefoxDriver(myProfile);
    driver.get(“https://mail.google.com”);
    }
    }

    Getting following error, not sure, what is being missing?

    Exception in thread “main” java.lang.NullPointerException
    at com.webdriver.tutorial.FirefoxSSLCertificate.main(FirefoxSSLCertificate.java:12)

    Please look into it and let me know.

  9. Pingback: Adding add-on in Firefox and Chrome using WebDriver | Abode QA

  10. Pingback: Email your failing Selenium WebDriver scripts’ Stack Trace to your Email Id | Abode QA

  11. Pingback: Unexpected error launching Internet Explorer. Protected Mode must be set to the same value | Abode QA

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>