question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to ignore ssl errors in headless chrome java

See original GitHub issue

Selenium headless chrome testing with java in unix returns empty page source as

<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html> which was due to accessing the secure http (https) website.

Is there a way to ignore the ssl certificate issue? Please let me know how to ignore it.

Selenium Version 3.7.1…java version 1.8.0.144 chrome driver version 2.33 Chrome Version 62+

I gave a try with options below…but it doesn’t seem to work.

1. ChromeOptions options = new ChromeOptions();
            options.setAcceptInsecureCerts(true);
            options.setHeadless(true);DesiredCapabilities capabilities = 
   DesiredCapabilities.chrome();
                capabilities.setCapability("chrome.switches", Arrays.asList("--
                ignore-certificate-errors,--web-security=false,--ssl-
                protocol=any,--ignore-ssl-errors=true"));
   capabilities.setCapability(ChromeOptions.CAPABILITY, options);
   driver = new ChromeDriver(capabilities);

2. DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
        capabilities.setCapability (CapabilityType.ACCEPT_INSECURE_CERTS, true);
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
   driver = new ChromeDriver(capabilities);

Am i doing this in a right way? Let me know the trick to make it work

Thanks in advance

Complete Code:

WebDriver driver = null;

        try {

            String filePath = "Path to driver";
            System.setProperty("webdriver.chrome.driver", filePath);

            ChromeOptions options = new ChromeOptions();
            options.addArguments("--headless");
            options.addArguments("--no-sandbox");
            options.setAcceptInsecureCerts(true);
            options.addArguments("test-type");

            String[] switches = {"--ignore-certificate-errors"};

            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            capabilities.setCapability("chrome.switches", Arrays.asList(switches));
            capabilities.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);

            driver = new ChromeDriver(capabilities);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            driver.get("https://meta.stackexchange.com");
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            System.out.println("PAGE SOURCE : \n" + driver.getPageSource());

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            driver.close();
            driver.quit();
        }

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

1reaction
c4bbagecommented, Sep 26, 2018

python script

capabilities = DesiredCapabilities.CHROME
capabilities['loggingPrefs'] = {'performance': 'ALL'}
capabilities['acceptInsecureCerts'] = True
1reaction
xyshiocommented, Sep 24, 2018

Hi Guys. I also encountered this problem and looks like solution for my case was adding into chrome options following capability types:

	  		chromeOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
	  		chromeOptions.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);

I hope will help you as well…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Headless chrome + ignore-certificate-errors - Stack Overflow
I need to get headless chrome to ignore certificate errors. The option is ignored when running in headless mode, and the driver returns ......
Read more >
Headless chrome + ignore-certificate-errors - Intellipaat
I need to get headless chrome to ignore certificate errors. The option is ignored when running in headless mode, and the driver returns ......
Read more >
Ignoring certificate errors in the headless browser
I am hitting a site with a wildcard certificate and the headless browser is returning ... Yes, just run Chrome with --ignore-certificate-errors.
Read more >
How to Handle SSL Certificate in Selenium WebDriver - Guru99
For handling SSL error in Chrome, we need to use desired capabilities of Selenium Webdriver. The below code will help to accept all...
Read more >
[Code example]-Headless chrome + ignore-certificate-errors
This thread confirms that --ignore-certificate-errors is ignored in headless mode. They mention about devtool protocol. Is it something I can invoke from java?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found