Friday, May 11

Handling Security Cerificates(UntrustedSSLCertificates) in Internet Explorer (IE) using WebDriver(selenium2)

In automating web based application we will find problem with Security Cerificates(UntrustedSSLCertificates).

And here is a simple solution for this.Just use the below code to cross the SSL page :)

driver.navigate().to("javascript:document.getElementById('overridelink').click()");


If you are using TestNG framework then here is the sample code :

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class SecurityCerts {

 WebDriver  driver;

 @BeforeTest
 public void setUpDriver(){ 
   driver = new InternetExplorerDriver();
    }

 @Test
 public void start(){
 driver.get("https://www.hs.facebook.com/help/community/question/?id=648015478541882");  
 driver.navigate().to("javascript:document.getElementById('overridelink').click()"); 
 }

}


3 comments:

  1. @Vamshi

    Can u pls explain what this statement exactly do...!
    driver.navigate().to("javascript:document.getElementById('overridelink').click()");

    ReplyDelete
  2. Niyati,

    In IE , If we want to cross the security error page then we have to click on "Continue to this website (not recommended)." link {this link element id is set to "overridelink" in the HTML code } .

    But if we try to click on this link using regular selenium syntax then it is not working i.e driver.findElement(By.id("overridelink")).click();

    So here is the workaround :

    driver.navigate().to("javascript:document.getElementById('overridelink').click()");

    OR

    driver.get("javascript:document.getElementById('overridelink').click()");

    Using javascript we are clicking on element for which id is set to "overridelink".

    note:
    When I was writing this post "https://flipkart.com/ " used to have security certificate error. Now there is no cert error :)

    ReplyDelete
  3. Got your point. Thank you so much :) for such a nice explanation.

    ReplyDelete