Accept Insecure Certificates

Avoid invalid certificate warning while testing using self-signed or invalid certificates

Introduction

Whenever you work with self-signed certificates or some server with a stale or untrusted certificate, most modern browsers display a security warning or invalid certificate errors.

To avoid these warnings and errors while running your automated tests on BrowserStack, use the acceptSslCerts capability.

Capability Description Expected values
acceptSslCerts Accept all SSL certificates A boolean. Default is False.
True if you want to accept all SSL certificates.

This capability has to be passed along with other capability declarations while starting a test session, as shown below:

// Accept any valid/invalid certificates
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("acceptSslCerts", "true");
// Accept any valid/invalid certificates
var capabilities = {
 "acceptSslCerts" : "true"
}
// Accept any invalid certificate

// For Chrome browser
OpenQA.Selenium.Chrome.ChromeOptions chromeCapability = new OpenQA.Selenium.Chrome.ChromeOptions();
capability.AddAdditionalCapability("acceptSslCerts", "true", true);

// For Edge browser
OpenQA.Selenium.Edge.EdgeOptions edgecapability = new OpenQA.Selenium.Edge.EdgeOptions();
capability.AddAdditionalCapability("acceptSslCerts", "true");

// For IE browser
OpenQA.Selenium.IE.InternetExplorerOptions ieCapability = new OpenQA.Selenium.IE.InternetExplorerOptions();
capability.AddAdditionalCapability("acceptSslCerts", "true", true);

// For Firefox browser
OpenQA.Selenium.Firefox.FirefoxOptions firefoxCapability = new OpenQA.Selenium.Firefox.FirefoxOptions();
capability.AddAdditionalCapability("acceptSslCerts", "true", true);

// For Safari browser
OpenQA.Selenium.Safari.SafariOptions safariCapability = new OpenQA.Selenium.Safari.SafariOptions();
safariCapability.AddAdditionalCapability("acceptSslCerts", "true");
# Accept any valid/invalid certificates
$caps = array(
 "acceptSslCerts" => "true"
);
# Accept any valid/invalid certificates
capabilities = {
 "acceptSslCerts": "true"
}
# Accept any valid or invalid certificates
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["acceptSslCerts"] = "true"
# Accept and valid/invalid certificates
my $capabilities = {
  "acceptSslCerts" => "true"
}
Important: While testing on the Safari browser or on iOS devices, if you want to navigate to a page in the middle of the test which has an invalid certificate, you have to additionally use the acceptSsl JavascriptExecutor (shown below) along with the acceptSslCerts capability.

JavascriptExecutor for Safari browser and iOS devices

If your use-case involves only an invalid certificate in the first URL that you visit in your test, then you do not need this custom Javascript executor.

This section is only required if your are testing on Safari or iOS devices and navigating to a URL with invalid certificate in the middle of the test through navigation commands such as click action, Javascript navigation, etc. Under such scenario you have to use both the acceptSslCerts capability explained above and the Javascript executor shown below.

Note: This JavascriptExecutor code must be executed after the stale/untrusted certificate webpage is loaded.

Following is the code snippet to use JavascriptExecutor to accept insecure certificates on Safari browser and on iOS devices:

driver.findElement(By.id(some-element)).click();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor:  {\"action\": \"acceptSsl\"}");
driver.findElement(webdriver.By.id('some-element')).click().then(function(){
  driver.executeScript("browserstack_executor: {\"action\": \"acceptSsl\"}").then(function()});
});
driver.FindElement(By.id("some-element")).Click();
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {\"action\": \"acceptSsl\"}");
$web_driver->findElement(WebDriverBy::id("some-element"))->click();
$web_driver->executeScript('browserstack_executor: {"action": "acceptSsl"}');
driver.find_element_by_id("some-element").click()
driver.execute_script('browserstack_executor: {"action": "acceptSsl"}')
caps["javascriptEnabled"]=true #Set `javascriptEnabled` capability to `true`
driver.find_element(:id, "some-element").click()
driver.execute_script('browserstack_executor: {"action": "acceptSsl"}')
$driver->find_element_by_id("some-element")->click('LEFT');
$driver->execute_script('browserstack_executor: {"action": "acceptSsl"}');

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert