- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to deal with security certificates using Selenium?
We can deal with security certificates using Selenium webdriver. We can have certificates like the SSL certificate and insecure certificate. All these can be handled with the help of the DesiredCapabilities and ChromeOptions class.
We shall create an object of the DesiredCapabilities class and apply setCapability method on it. Then pass the CapabilityType and value as parameters to that method.
These general browser chrome profiles shall be fed to the object of the ChromeOptions class for the local browser with the help of the merge method. Finally, this information needs to be passed to the webdriver object.
Syntax
DesiredCapabilities c=DesiredCapabilities.chrome(); c.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true); c.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); ChromeOptions opt= new ChromeOptions(); opt.merge(c);
Example of a SSL certificate is shown below. We need to click on the Proceed anyway button to accept this certificate.
Example of Insecure certificate is shown below −
Example
import org.openqa.selenium.WebDriver; import org.openqa.selenium.Capabilities; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class SecurityCertAccepts{ public static void main(String[] args) { //DesiredCapabilities object DesiredCapabilities c=DesiredCapabilities.chrome(); //accept insecure certificates c.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true); //accept SSL certificates c.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); //ChromeOptions object ChromeOptions opt= new ChromeOptions(); //merging browser profiles opt.merge(c); System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); // configure options parameter to Chrome driver WebDriver driver = new ChromeDriver(opt); } }
- Related Articles
- How to deal with ModalDialog using selenium webdriver?
- How to deal with reusable components in Selenium Java?
- What are Digital Certificates in information security?
- How to deal with Garbage?
- How to deal with stubborn children?
- How to Deal With Team Attrition
- How to Deal With Inconsiderate People?
- How to deal with a cynical boss?
- How to deal with a cranky baby?
- How to Deal with Threats and Opportunities
- How to Deal with A Lying Spouse
- How to deal with NaN values while plotting a boxplot using Python Matplotlib?
- How Ringworm Spreads and, how to Deal with it?
- How to scroll down using Selenium WebDriver with Java?
- How to scroll to element with Selenium WebDriver using C#?
