How to handle security certification errors using selenium web drivers & eclipse
- Below is one of the approach on how to handle https (i.e. approves security certificate) for websites when your test script is being executed for Internet Explorer.
While accessing any website, you may have come across the message that is shown below;
So here we actually need to click the second option i.e. "Continue to this website (not recommended)." to access the website and for doing so we are taking help of Java script to click the link.
This is basically the code for handling https site;
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class WD_Class {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
//For Launching IE browserInternet explorer
System.setProperty("webdriver.ie.driver", "C:\\Jar\\IEDriverServer.exe");
driver=new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@Test
public void WD_Class() throws Exception {
driver.get("https://xsy.detail.com/main.aspx"); //Specific the web site URL which ask to approve security certificate
driver.navigate().to("javascript:document.getElementById('overridelink').click()"); //Java script to click the link
Thread.sleep(5000);
Assert.assertEquals(driver.getTitle(), "Page title"); //assert the title of the web page
System.out.println("Success");
Thread.sleep(5000);
//For Launching IE browserInternet explorer
System.setProperty("webdriver.ie.driver", "C:\\Jar\\IEDriverServer.exe");
driver=new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@Test
public void WD_Class() throws Exception {
driver.get("https://xsy.detail.com/main.aspx"); //Specific the web site URL which ask to approve security certificate
driver.navigate().to("javascript:document.getElementById('overridelink').click()"); //Java script to click the link
Thread.sleep(5000);
Assert.assertEquals(driver.getTitle(), "Page title"); //assert the title of the web page
System.out.println("Success");
Thread.sleep(5000);
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}