8

Its been a while I'm trying to figure out a way to automatically accept SSL certs. But unfortunately no luck. So, here is the case, I'm working on selenium tests. And, every time when I run the test on chrome, a small pop-up appears asking to select a certificate.

I tried this in python: How to deal with certificates using Selenium?

I also tried (in javascript): var options = new chrome.Options();
options.addArguments("--ignore-certificate-errors")

But it doesn't seems to work!

In firefox, there is an option to automatically selects certs. Is there any way in selenium or in chrome settings which automatically selects the certs? Will ENTER/RETURN keys in selenium work?

EDITED: Below is my code. Is this the right way to use?

var launch = function(){
var options = new chrome.Options();
options.addArguments("--test-type"); 
/* Also tried options.addArguments(“--ignore-certificate-errors")
*/
var driver = new webdriver.Builder()
.usingServer('http://127.0.0.1:4444/wd/hub')
.setChromeOptions(options)
.build();
driver.get(url)
}

P.S Here, I'm using JavaScript.

Community
  • 1
  • 1
Dana
  • 139
  • 1
  • 10
  • Use `--disable-web-security` – SLaks Nov 16 '15 at 20:17
  • @SLaks Using your command it still asks for certs. – Dana Nov 16 '15 at 20:34
  • Try starting chrome with option `--ignore-certificate-errors`. See http://peter.sh/experiments/chromium-command-line-switches/ – Steffen Ullrich Nov 16 '15 at 21:37
  • @SteffenUllrich Thanks! It works when I pass this command in the terminal like this: chrome.exe --ignore-certificate-errors. But how do I pass in the same argument in the selenium code. I tried this: var options = new chrome.Options(); options.addArguments("--ignore-certificate-errors"); And this doesn't seems to work. Any suggestions? – Dana Nov 16 '15 at 22:45
  • @SteffenUllrich chrome.exe --ignore-certificate-errors This doesn't seems to work any more! – Dana Nov 16 '15 at 23:07
  • Please post your complete code. Chrome options should work. – Shamik Nov 17 '15 at 06:35
  • @Shamik Edited my question. Please have a look – Dana Nov 17 '15 at 22:48

4 Answers4

2

ACCEPT_SSL_CERTS is one of the browser's desired capability that tells the browser to accept / deny ssl certificates by default.

below is a sample code for accepting SSL certificates in chrome:

DesiredCapabilities cap=DesiredCapabilities.chrome();

// Set ACCEPT_SSL_CERTS  variable to true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path
System.setProperty("webdriver.chrome.driver","Chrome driver path");

// Open browser with capability
WebDriver driver=new ChromeDriver(cap);
Shantanu Kher
  • 1,014
  • 1
  • 8
  • 14
Navpreet Singh
  • 141
  • 1
  • 5
1

It is major problem with Chrome versions above v.80. I am currently using version 84.0.4147.105 which won't accept or ignore SSL certificate. The one thing to do is to downgrade Chrome version below v.80, especially for those of you who are building test cases in local Host applications.

1

Example using Selenium-grid and Chrome

const { Builder, until, By } = require("selenium-webdriver");

const capabilities = {
  browserName: "chrome",
  acceptInsecureCerts: true,
};

// alternative require `Capabilities` and do like this:
// const capabilities = Capabilities.chrome().setAcceptInsecureCerts(true);

try {
  const driver = await new Builder()
    .usingServer("http://localhost:4444/wd/hub")
    .withCapabilities(capabilities)
    .build();

  await driver.get("https://frontend");

  // tests
  const el = await driver.wait(until.elementLocated(By.id("root")), 2000);
  await driver.wait(until.elementIsVisible(el), 2000);
  expect(el).not.toBeNull();

  // tear down
  await driver.quit();
} catch (err) {
  throw new Error(err);
}
rabinage
  • 11
  • 2
-1
        chrome_options = ChromeOptions()
        chrome_options.add_argument('--lang='+language)
        chrome_options.add_argument('--ignore-certificate-errors')
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--allow-running-insecure-content')
        chrome_options.add_argument('--disable-web-security')
        chrome_options.add_experimental_option('useAutomationExtension', False)
        if headless :
            chrome_options.set_headless()
        if remote :
            self.driver = webdriver.Remote(command_executor=wd,desired_capabilities=chrome_options.to_capabilities(),options=chrome_options) 
        else:
            self.driver = webdriver.Chrome(desired_capabilities=chrome_options.to_capabilities(),options=chrome_options) 
Cam
  • 1