Top community members

Welcome to Dirask IT community! ā¤ šŸ’»
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

[Edit]
EN

Selenium - accept untrasted certificates in Google Chrome Browser with Java

4 points
Created by:
Ticket Ninja
2332

In this short article IĀ would like to show how to accept by Google Chrome Browser untrusted certificates and use them with Selenium in Java.

There are 3 solutions:

  • use trusted certificate or use certificate manager to add it to proper store,
  • write tool that confirm certificate before propert testing,
  • useĀ setAcceptInsecureCerts method and ignore that warnings.

In this article we useĀ 3rd solution.

The solution is usefulĀ when writtenĀ e2e tests with Selenium useĀ httpsĀ protocol andĀ certificate is untrusted (e.g. was generated by yourself, expired, etc.).

Quick solution:

ChromeOptions options = new ChromeOptions();

// add following flag
options.setAcceptInsecureCerts(true);

Full example:Ā 

package logic.selenium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class SeleniumUtil {

    public static WebDriver createWebDriver() {

        System.setProperty("webdriver.chrome.driver", "C:\\Projects\\tools\\chromedriver.exe");

        ChromeOptions options = new ChromeOptions();

        options.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
        options.setHeadless(false);
        options.setAcceptInsecureCerts(true);

        options.addArguments("--window-position=100,30");
        options.addArguments("--window-size=1700,1000");
        // options.addArguments("--start-maximized");
        options.addArguments("--disable-extensions");
        options.addArguments("--disable-gpu");
        options.addArguments("--no-sandbox");

        return new ChromeDriver(options);
    }
}

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey šŸ‘‹
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more