Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & Test Observability

Accept insecure certificates

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

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 following capability.

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

If you are using BrowserStack SDK, you can set the following capabilities in the browserstack.yml file:

browserstack.yml
Copy icon Copy snippet

You can use either Selenium 4 or Selenium Legacy JSON to organize your tests.

BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.

Capability Description Expected values
acceptInsecureCerts 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 capabilities = new DesiredCapabilities();
capabilities.setCapability("acceptInsecureCerts", "true");
// Accept any valid/invalid certificates
var capabilities = {
	"acceptInsecureCerts" : "true"
}
// Accept any invalid certificate

OpenQA.Selenium.Chrome.ChromeOptions capability = new OpenQA.Selenium.Chrome.ChromeOptions();
capability.AddAdditionalOption("acceptInsecureCerts", true);
# Accept any valid/invalid certificates
$caps = array(
	"acceptInsecureCerts" => "true",
)
# Accept any valid/invalid certificates
from selenium.webdriver.chrome.options import Options
options = Options()
options.accept_insecure_certs = True
# Accept any valid or invalid certificates
options = Selenium::WebDriver::Options.chrome
options.accept_insecure_certs = true
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
DesiredCapabilities capability = new DesiredCapabilities();
capability.AddAdditionalCapability("acceptSslCerts", "true", 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"

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 capability as shown below.

JavascriptExecutor for Safari browser and iOS devices

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 capability explained above and the Javascript executor shown below.

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"}')
#Set `javascriptEnabled` capability to `true`
driver.find_element(:id, "some-element").click()
driver.execute_script('browserstack_executor: {"action": "acceptSsl"}')

Check this page for a list of various JavaScript Executors that BrowserStack offers.

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
Download Copy