FAQ: SSL Error (or) Security Certificates Handling
There are times when we open a webpage and it displays a warning saying that
"This web page is not trusted/Secured." It may ask, "Do you want
to continue?" This happens when the website is not secured or trusted,
leading to a security certificate error.
When :
if website is not secured /
trusted, it displays Security ceritificate error
Click continue to open the web site
with out handling Certificate error:
package SecurityDownloadsBasics;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class HandlingCertificateErrors {
public static
void main(String[] args) {
//
TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
".\\Drivers\\chromedriver.exe");
//
// // //open chrome browser
WebDriver driver =
new ChromeDriver(); // Def
constr
driver.get("https://expired.badssl.com/");
//
Your connection is not private
// Attackers might be trying
to steal your information from expired.badssl.com (for example, passwords,
messages, or credit cards). Learn more
// NET::ERR_CERT_DATE_INVALID
// HW
click advanced > ClicK Proceed button
}
}
Handling
Certificate error using "ChromeOptions":
// ChromeOptions-is predefined class in Selenium
//can
be used to apply Different settings/ to
apply Different options to chrome
browser
//
// to accept Security certificate
------------------------------
package UploadfileBasics;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import com.sun.tools.classfile.StackMapTable_attribute.chop_frame;
public class HandlingCertificateErrorsUsingChromeOptions {
public static
void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
".\\Drivers\\chromedriver.exe");
//
Handle security certificate error -->
use ChromeOptions -class
//
create obj for ChromeOptions-class
ChromeOptions
chOptions = new ChromeOptions();
//
accepts security certificate error -->
some method
chOptions.setAcceptInsecureCerts(true);
// pass
true value
// inform browser with above settings/pass
chromeoptions ref var in chromedriver
// // //open chrome browser
// WebDriver
driver= new ChromeDriver();// no
parameter (or) DC
WebDriver
driver = new ChromeDriver(chOptions);
// 1
PC
//
while opening chrome browser - it opens with given options/ settings
driver.get("https://expired.badssl.com/");// // no
certificate error
// check
certificate error --> wont display
SSL error now
System.out.println("ends
here");
}
}
-----------------
// HW handle SSL error in Edge browser, Firefox browser
// chrome
--> ChromeOptions -class
// edge
browser --> EdgeOptions -class
// firefox
browser --> FirefoxOptions
// Ie
browser-- > InternetExplorerOptions
// EdgeOptions
// FirefoxOptions
// InternetExplorerOptions
SSL - Secure
Socket Layer
An SSL certificate is a digital certificate that authenticates a
website's identity and enables an encrypted connection.
SSL stands for Secure Sockets Layer, a security protocol that
creates an encrypted link between a web server and a web browser.
Refer:
https://www.kaspersky.com/resource-center/definitions/what-is-a-ssl-certificate
FAQ: How can u handle
certificate error (or) SSL error?
No comments:
Post a Comment