• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Basic Selenium / How to Handle Untrusted Certificate Selenium Webdriver

How to Handle Untrusted Certificate Selenium Webdriver

November 20, 2017 by Mukesh Otwani 41 Comments

Handle Untrusted Certificate Selenium

Hello, Welcome to Selenium tutorial in this post we will see how to Handle Untrusted Certificate Selenium.

 

  • What is Untrusted SSL certificate? Whenever We try to access HTTPS website or application so many time you will face  untrusted SSL certificate issue. This issue comes in all browser like IE, Chrome,Safari, Firefox etc.

Handle Untrusted Certificate Selenium

2-       Why we get this certificate issues often?

 

Handle Untrusted Certificate Selenium

This certificates some in multiple conditions and we should know all of them so that we can rectify them easily.

1- Each secure site has Certificate so its certificate is not valid up-to-date.

2– Certificate has been expired on date

3– Certificate is only valid for (site name) 


4- 
The certificate is not trusted because the issuer certificate is unknown due to many reasons.

 

Handle Untrusted Certificate Selenium

Step 1-We have to create FirefoxProfile in Selenium.

Step 2- We have some predefined method in Selenium called setAcceptUntrustedCertificates() which accept Boolean values(true/false)- so we will make it true.

Step 3-Open Firefox browser with the above-created profile.

 

I have published video on the same.

 

Handle untrusted certificate in Firefox

 

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class SSLCertificate {

public static void main(String[] args) {

//It create firefox profile
FirefoxProfile profile=new FirefoxProfile();

// This will set the true value
profile.setAcceptUntrustedCertificates(true);

// This will open  firefox browser using above created profile
WebDriver driver=new FirefoxDriver(profile);

driver.get("pass the url as per your requirement");


}

}

 

Since Firefox comes default browser in Selenium so for other browsers like Chrome, IE, Safari we have to use below technique.

Handle untrusted certificate in Chrome

 // Create object of DesiredCapabilities class
DesiredCapabilities cap=DesiredCapabilities.chrome();

// Set ACCEPT_SSL_CERTS  variable to true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path
System.setProperty("webdriver.chrome.driver","Chrome driver path");

// Open browser with capability
WebDriver driver=new ChromeDriver(cap);

 

Handle untrusted certificate in IE

// Create object of DesiredCapabilities class

DesiredCapabilities cap=DesiredCapabilities.internetExplorer();

// Set ACCEPT_SSL_CERTS  variable to true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path
System.setProperty("webdriver.ie.driver","IE driver path");

// Open browser with capability
WebDriver driver=newInternetExplorerDriver(cap);

  Handle untrusted certificate in Safari

// Create object of DesiredCapabilities class

DesiredCapabilities cap=DesiredCapabilities.safari();

// Set ACCEPT_SSL_CERTS  variable to true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path
System.setProperty("webdriver.safari.driver","Safari driver path");

// Open browser with capability
WebDriver driver=new SafariDriver(cap);

I would suggest you add above code in Base Class in Selenium Webdriver so you don’t have to write code again and again.

I have implemented in my office project and found good results.

Thanks for visiting my blog. Please comment below if you finding any issue.

Keep in touch. Have a nice day :)

Filed Under: Basic Selenium Tagged With: Untrusted Certificate Selenium

Reader Interactions

Comments

  1. Omair Imran says

    March 29, 2020 at 2:11 AM

    Hi Mukesh,

    I hope u doing great. I m automating my project. One of my test cases is to sign-up using Gmail But when executing sign-up using Gmail, after typing username and click the next button, Chrome show error

    “This browser or app may not be secure. Learn more
    Try using a different browser. If you’re already using a supported browser, you can refresh your screen and try again to sign in.”

    Can you help me with this? Looking forward to your reply

    Thanks

    Regards
    Omair

    Reply
    • Mukesh Otwani says

      March 29, 2020 at 6:54 PM

      Hi Omair,

      Google has restricted the usage of automation of Google account sign up and sign in action. Google considers this as bots. You can use this link https://opensource-demo.orangehrmlive.com/ for your learning purpose

      Reply
  2. Gaurav Varma says

    February 4, 2020 at 4:26 PM

    Hi Mukesh,

    Why we are creating a profile for firefox? Why can’t we use DesiredCapabilites or firefox options for firefox?

    Reply
    • Mukesh Otwani says

      February 4, 2020 at 5:43 PM

      Hi Gaurav,

      The above blog post is for Selenium 2.xx. Now Selenium 3.6 version onwards gecko driver has introduced FirefoxOptions similar to ChromeOptions. If you are using latest Selenium version then use FirefoxOptions

      Reply
  3. vishnu verma says

    April 10, 2019 at 6:57 PM

    Hi Mukesh,

    I tried your code for chrome browser and it is not working.

    My Chrome Version: 69
    Selenium Version : 2.52.0

    Getting SSL pop up everytime after entering the URL although i have added that certificate in my chrome browser as well.

    Thanks
    Vishnu Verma

    Reply
    • Mukesh Otwani says

      April 10, 2019 at 7:20 PM

      Hi Vishnu,

      Try this code…
      ChromeOptions option = new ChromeOptions();
      option.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
      WebDriver driver = new ChromeDriver(option);

      Reply
  4. Sanjay says

    December 27, 2016 at 3:39 PM

    Hi Mukesh,
    I tried both DesiredCapabilities and FirefoxProfile option, but still facing issue in launching https URLs like google,facebook. FF 50 and SE 3.0.1, also i tried with 2.53.1 but getting same issue

    Reply
    • Mukesh Otwani says

      December 28, 2016 at 11:21 AM

      Hi Sanjay,

      I just tried and I am able to handle certificate.

      Reply
      • Nirimakhi says

        January 10, 2017 at 5:45 PM

        Hi Mukesh ,

        I tried both DesiredCapabilities and
        driver.get(“ur app URL”);
        driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);
        to handle SSL for IE 11 browser . But its worn’t work for me .
        Can you please tell how to handle SSL for IE 11browser .

        Below is the SSL message . which we need to handle .
        “We recommend that you close this webpage and do not continue to this website. “.

        Thank You.

        Reply
        • Mukesh Otwani says

          January 10, 2017 at 7:46 PM

          Hi there,

          The code statements you have written over are correct. Moreover you need to check Internet Options security. For this please visit this link http://learn-automation.com/challenges-with-ie-browser-in-selenium-webdriver/

          Reply
  5. Bhavik says

    December 1, 2016 at 3:05 PM

    Hi Mukesh,
    I tried both DesiredCapabilities and FirefoxProfile option, but still facing issue in launching https URLs like google,facebook. FF 50 and SE 3.0.1

    Reply
    • Mukesh Otwani says

      December 6, 2016 at 12:40 PM

      Hi Bhavik,

      Yes it is issue with Selenium 3 so you can try with 2.53.1

      Reply
  6. Venu Yalluri says

    October 21, 2016 at 10:17 PM

    profile.setAcceptUntrustedCertificates(true);
    WebDriver driver=new FirefoxDriver(***profile***);

    Mukesh, you also seem to have forgotten to pass the profile object in your first piece of code. With SSL certs it is difficult to test whether or not the code works even without passing this object. My contention is it won’t.
    Example:
    profile.setPreference(“browser.startup.homepage”, “http://google.com”);
    If we try the above line of code (that sets the profile homepage) with the below 2 statements separately, it works only when the profile object is passed as a parameter.
    WebDriver driver = new FirefoxDriver(profile);
    AND
    WebDriver driver = new FirefoxDriver();

    Not sure if this one too was unintentional. Please let me know what you think.

    Reply
    • Mukesh Otwani says

      October 25, 2016 at 2:11 PM

      Thanks Venu and post updated.

      Reply
  7. Venu Yalluri says

    October 19, 2016 at 6:59 PM

    WebDriver driver=new SafariDriver(***cap***);

    You forgot passing the “cap” instance in your last line of code.
    A minor typo but worth correcting.

    Reply
    • Mukesh Otwani says

      October 20, 2016 at 1:55 PM

      Hey Venu,

      Thank you. Post updated 🙂

      Reply
  8. Sreenath says

    October 17, 2016 at 10:19 AM

    Hi Mukesh,
    I am using your tutorial to learn Selenium. Now I have come so far in Selenium. Thanks for these tutorials and videos. You are a good teacher and its helping me alot.

    I have one doubt regarding use of thread. I find your codes are having thread command . Is it good to use thread (sleep) in code.? In real application are we using it? or can we use it?

    Reply
    • Mukesh Otwani says

      October 18, 2016 at 2:29 PM

      sleep method is not good practise to use.

      Kindly refer http://learn-automation.com/explicit-wait-in-selenium-webdriver/

      Reply
  9. swapna says

    September 12, 2016 at 9:26 PM

    Hi

    This is my code

    public static void main(String[] args) {

    DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    System.setProperty(“webdriver.ie.driver”, “C:\\Selenum\\IEDriverServer_x64_2.53.1\\IEDriverServer.exe”);

    WebDriver driver = new InternetExplorerDriver(cap);

    driver.get(“https://10.216.2.59/BritishLand/Live/Themes/Tabs/Login.aspx?ReturnUrl=%2fBritishLand%2flive”);

    but still getting the same page

    Reply
    • Mukesh Otwani says

      September 12, 2016 at 10:57 PM

      HI Swapna,

      Try this as well for IE browser

      driver.get(“https://xyz.com”);
      //now we are going to use javascipt ,This will click on “Continue to this website (not recommended)” text and will //push us to the page
      driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);

      Reply
  10. Jithendra Reddy K says

    August 16, 2016 at 2:11 PM

    Very Nice Explanation and information. Cheers!!!

    Reply
    • Mukesh Otwani says

      August 18, 2016 at 9:39 AM

      Thanks Jithendra 🙂

      Reply
  11. Vishnu Godse says

    July 15, 2016 at 2:39 PM

    Hi Mukesh,

    yesterday i have gone through your 03 videos [Generate Logs using Logger, Security Certificate,Windows Popup handling].

    i was strangling from 01 week to clear this things but yesterday i have followed you videos and created sample application and within 40 Minutes i learnt all these.

    I have few questions [small questions]:

    1. which is better CSS or XPATH and why ?
    2. How you will control page if Network Goes down while entering data in selenium webdriver

    Thanks,
    Vishnu GOdse

    Reply
    • Mukesh Otwani says

      July 20, 2016 at 2:14 PM

      Hey Vishnu,

      Really happy to see nice comment 🙂 Hope my future videos will also help you.

      Please find my answers

      1. which is better CSS or XPATH and why ?
      Ans- CSS is faster and it works same in all browser. Xpath works fine with FF and Chrome.

      2. How you will control page if Network Goes down while entering data in selenium webdriver
      Ans- If network goes down it will throw no such element exception. To handle this you can use smart wait.

      Reply
  12. Prachee Jain says

    May 31, 2016 at 11:46 AM

    What is the difference in profileini and firefoxfile() method, profileini also use for SSL Error??

    Reply
  13. Prachee Jain says

    May 27, 2016 at 2:14 PM

    will this code also work for “Error code: sec_error_unknown_issuer”

    Reply
    • Mukesh Otwani says

      May 30, 2016 at 12:36 AM

      Yes it should work.

      Reply
      • Richmond says

        July 20, 2016 at 1:54 PM

        Mine did not :'(

        Reply
        • Mukesh Otwani says

          July 20, 2016 at 2:17 PM

          Hi Richmond,

          In this browser you tried?

          Reply
          • Richmond says

            July 21, 2016 at 7:33 AM

            Im using Firefox47, using marionette and im using RemoteWebDriver

          • Mukesh Otwani says

            July 25, 2016 at 12:24 PM

            Hey Richmond,

            I have not used marionette so not sure on this 🙁 why dont you use FF 46 ?

  14. Vidya says

    April 12, 2016 at 5:13 PM

    very nicely explained…keep it up with a good work @Mukesh

    Reply
    • Mukesh Otwani says

      April 13, 2016 at 10:51 PM

      Thanks Vidya, Let me know if any help from my side.

      Reply
  15. BG says

    April 5, 2016 at 8:40 AM

    I tried with IE11 and it didn’t work for the site driver.get(“https://cacert.org/”); could you please check.

    Reply
    • Mukesh Otwani says

      April 5, 2016 at 4:42 PM

      Let me try and will update u soon.

      Reply
  16. Raja says

    December 8, 2015 at 3:07 PM

    Thanks you!

    Reply
    • Mukesh Otwani says

      December 8, 2015 at 9:54 PM

      Thanks Raja

      Reply
  17. Lajish Lakshmanan says

    October 6, 2015 at 4:56 PM

    Hi there,

    I am trying to use selenium webdriver for Safari browser. As you mentioned in your post regarding Safari launching, I’ve one doubt. Do we need to provide safari driver path because it is available as extension to Safari browser which we can install it as ‘Open With’ option in windows-> Safari.

    And if you go to Safari Settings-> Preferences-> Extensions tab. Here I’ve already enabled it

    Could you pls put some light over this.

    Regards,
    Lajish Lakshmanan

    Reply
    • Mukesh Otwani says

      October 6, 2015 at 5:54 PM

      Hi Lajish,

      Currently safari extension is available for 2.45 only so you can use Selenium version 2.45 or lower it will work fine. Right now i tried with 2.40 its working fine in my machine.

      Reply
      • Lajish Lakshmanan says

        October 6, 2015 at 6:02 PM

        Hi there,

        Do i need to provide safari driver path ?
        As same thing is already available as extension to browser.

        Reply
        • Mukesh Otwani says

          October 6, 2015 at 7:51 PM

          No Lajish, just install the extension and it will work. Previously we had driver for safari browser but now extension will perform the same thing.

          Reply

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?