Thursday, September 12, 2019

Post#21.Handle SSL Certificate issue


setAcceptInsecureCerts in selenium

SSL (Secure Socket Layer) Certificate is nothing but encrypted way of transmitting data from the website to database, database to website.

If a site enables its SSL certificate we can see https protocol instead of http protocol. Few companies will have their own certificates and few companies will buy from the SSL providing companies.


Sometimes some sites will open only when you open them in https mode, there are few more site whatever you open they will open only with https protocol.

setAcceptInsecureCerts method present in the ChromeOptions/FirefoxOptions/InternetExplorerOptions class will help us to bypass the SSL certificate.
setAcceptInsecureCerts method accepts boolean parameter, if true driver accepts the certificate and proceeds further, if false is passed and site has SSL then driver will stop the execution as it cannot procees further due to SSL.

public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "D:\\PATH\\geckodriver.exe");
                        FirefoxOptions fo = new FirefoxOptions();
                        // accept the certificate
                        fo.setAcceptInsecureCerts(true);
                        //open the browser
                        WebDriver driver = new FirefoxDriver(fo);
                        driver.get("https://www.cacert.org/");
            }
The sites having https may or may not throw the certificate warning, if a site throws a certificate warning(below image) then only this method serves its purpose, otherwise this method does not have any effect.



1 comment:

  1. This article is an appealing wealth of useful informative that is interesting and well-written. I commend your hard work on this and thank you for this information. I know it very well that if anyone visits your blog, then he/she will surely revisit it again. CE certificate

    ReplyDelete