title: How to accept insecure certificates in Chrome using Selenium-Webdriver for JavaScript?
body: <p>I have generated test script using Selenium-IDE. It is of type Javascript-Mocha. I have an environment ready to test it locally.
  So, I am accessing a remote url that has insecure certificate issue.</p>
  
  <p>I need to modify the generated TestScript for chrome capability to accept insecure certificate.
  I couldn't find any official documentation for JavaScript nor any good blog or StackOverflow answer.</p>
  
  <p>Here's the generated test script:</p>
  
  <pre><code>// Generated by Selenium IDE
  
  const {
    Builder,
    By,
    Key,
    until
  } = require('selenium-webdriver')
  const assert = require('assert')
  
  describe('work', function() {
    this.timeout(30000)
    let driver
    let vars
  
  
    beforeEach(async function() {
      driver = await new Builder().forBrowser('chrome').build()
      vars = {}
    })
  
    afterEach(async function() {
      driver = await new Builder().forBrowser('chrome').build()
      await driver.quit();
    })
    it('work', async function() {
      await driver.get("https://kwras.eu.company.com:10016/front/v9/signin")
      await driver.manage().window().setRect(704, 584)
      await driver.findElement(By.id("prod-signin-basic-signin-form-username")).sendKeys("srishti")
      await driver.findElement(By.id("prod-signin-basic-signin-form-password")).sendKeys("srpass")
      await driver.findElement(By.id("ui-id-1")).click()
      await driver.findElement(By.css(".icon-ham-menu")).click() {
        const element = await driver.findElement(By.css(".icon-ham-menu"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      } {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.css("#ui-id-17 &gt; .oj-navigationlist-item-label")).click() {
        const element = await driver.findElement(By.css("#ui-id-17 &gt; .oj-navigationlist-item-label"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      }
      await driver.executeScript("window.scrollTo(0,0)") {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.css("#ui-id-34 &gt; .oj-navigationlist-item-label")).click() {
        const element = await driver.findElement(By.css("#ui-id-34 &gt; .oj-navigationlist-item-label"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      }
      await driver.executeScript("window.scrollTo(0,0)") {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.css("#ui-id-49 &gt; .oj-navigationlist-item-label")).click() {
        const element = await driver.findElement(By.css("#ui-id-49 &gt; .oj-navigationlist-item-label"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      } {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.id("ui-id-55")).click() {
        const element = await driver.findElement(By.id("ui-id-55"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      }
      await driver.executeScript("window.scrollTo(0,0)")
      await driver.findElement(By.css("#searchData\\3A_hdrCol0_-2063926153_2 &gt; #dottedMenu .oj-button-label &gt; .demo-icon")).click() {
        const element = await driver.findElement(By.css("#searchData\\3A_hdrCol0_-2063926153_2 &gt; #dottedMenu .oj-button-label &gt; .demo-icon"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      } {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.css("#ui-id-63 &gt; span")).click()
      await driver.findElement(By.css("#oj-collapsible-Identification-header &gt; .font16")).click()
      await driver.findElement(By.css("#oj-collapsible-Brand-header &gt; .font16")).click()
      await driver.findElement(By.css("#oj-collapsible-Dates-header &gt; .oj-component-icon")).click()
    })
  })
  </code></pre>
  
  <p>I tried to modify in the following way (commented lines are my modified code):</p>
  
  <pre><code>// Generated by Selenium IDE
  //var webdriver = require("selenium-webdriver")
  const {
    Builder,
    By,
    Key,
    until
  } = require('selenium-webdriver')
  const assert = require('assert')
  
  describe('work', function() {
    this.timeout(30000)
    let driver
    let vars
    //var cbtHub = "http://localhost:4444/wd/hub  ";
    //var caps = {
    //  browserName: 'Chrome',
    //  acceptSslCerts: true,
  
    //};
  
    beforeEach(async function() {
      //try {
      //  driver = new webdriver.Builder()
      //    .usingServer(cbtHub)
      //    .withCapabilities(caps)
      //    .build();
      //} catch (err) {
      //  console.log(err);
      //  handleFailure(err, driver)
      //}
      driver = await new Builder().forBrowser('chrome').build()
      vars = {}
  
    })
    afterEach(async function() {
      driver = await new Builder().forBrowser('chrome').build()
      await driver.quit();
    })
    it('work', async function() {
      await driver.get("https://kwras.eu.company.com:10016/front/v9/signin")
      await driver.manage().window().setRect(704, 584)
      await driver.findElement(By.id("prod-signin-basic-signin-form-username")).sendKeys("srishti")
      await driver.findElement(By.id("prod-signin-basic-signin-form-password")).sendKeys("srpass")
      await driver.findElement(By.id("ui-id-1")).click()
      await driver.findElement(By.css(".icon-ham-menu")).click() {
        const element = await driver.findElement(By.css(".icon-ham-menu"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      } {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.css("#ui-id-17 &gt; .oj-navigationlist-item-label")).click() {
        const element = await driver.findElement(By.css("#ui-id-17 &gt; .oj-navigationlist-item-label"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      }
      await driver.executeScript("window.scrollTo(0,0)") {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.css("#ui-id-34 &gt; .oj-navigationlist-item-label")).click() {
        const element = await driver.findElement(By.css("#ui-id-34 &gt; .oj-navigationlist-item-label"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      }
      await driver.executeScript("window.scrollTo(0,0)") {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.css("#ui-id-49 &gt; .oj-navigationlist-item-label")).click() {
        const element = await driver.findElement(By.css("#ui-id-49 &gt; .oj-navigationlist-item-label"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      } {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.id("ui-id-55")).click() {
        const element = await driver.findElement(By.id("ui-id-55"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      }
      await driver.executeScript("window.scrollTo(0,0)")
      await driver.findElement(By.css("#searchData\\3A_hdrCol0_-2063926153_2 &gt; #dottedMenu .oj-button-label &gt; .demo-icon")).click() {
        const element = await driver.findElement(By.css("#searchData\\3A_hdrCol0_-2063926153_2 &gt; #dottedMenu .oj-button-label &gt; .demo-icon"))
        await driver.actions({
          bridge: true
        }).moveToElement(element).perform()
      } {
        const element = await driver.findElement(By.CSS_SELECTOR, "body")
        await driver.actions({
          bridge: true
        }).moveToElement(element, 0, 0).perform()
      }
      await driver.findElement(By.css("#ui-id-63 &gt; span")).click()
      await driver.findElement(By.css("#oj-collapsible-Identification-header &gt; .font16")).click()
      await driver.findElement(By.css("#oj-collapsible-Brand-header &gt; .font16")).click()
      await driver.findElement(By.css("#oj-collapsible-Dates-header &gt; .oj-component-icon")).click()
    })
  })
  </code></pre>
  
  <p>But I am getting the following error:
  <a href="https://i.stack.imgur.com/2aex0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2aex0.png" alt="enter image description here"></a></p>
  
  <p>How do I add accept insecure ssl certificate chrome capability using Javascript for selenium-webdriver? Any link to the official documentation for Javascript capability using selenium-webdriver, would also be very helpful.</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE:</strong>
  Following @balint's suggestion, I have updated the way I'm initializing the builder, like this:</p>
  
  <pre><code>var chromeCapabilities = Capabilities.chrome();
  chromeCapabilities. setAcceptInsecureCerts(true);
  var driver = new Builder().withCapabilities(chromeCapabilities).build();
  </code></pre>
  
  <p>The key part is <code>setAcceptInsecureCerts</code>, which is a method I found in the <a href="https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/lib/capabilities.js#L387" rel="nofollow noreferrer">source code</a>. Inspite of this the test is still not able to accept the insecure certificate and move on to the website.</p>