Trying to find a way to disable Firefox from raising a warning every time a connection uses an "untrusted" certificate, with Selenium. I believe that the kind of solution that would work the best would be to set one of the browser preferences.

- 4,271
- 8
- 34
- 56

- 11,900
- 22
- 62
- 102
-
Firefox usually does not show certificate error screen. By default it is handled in firefox and chrome. Only IE it is not handled. – Vinay Oct 17 '13 at 05:29
-
@JuanCarlosCoto For fixing the issue, you might also have a look at my answer on [How to disable “This Connection is Untrusted” Certificate in FireFox?](http://stackoverflow.com/questions/21709095/how-to-disable-this-connection-is-untrusted-certificate-in-firefox/37080038#37080038) Hope this helps... – Murat Yıldız May 06 '16 at 19:37
16 Answers
Just found this from the Mozilla Foundation bug link and it worked for me.
caps.setCapability("acceptInsecureCerts",true)

- 945
- 10
- 8
-
I'm running Selenium throught nightwatch.js, and this worked for me as well. (`"acceptInsecureCerts": true`) – Adrian Schmidt May 17 '17 at 09:10
I found this comment on enabling this functionality in Selenium for Java. There is also this StackOverflow question about the same issue, also for Java For Python, which was my desired target language, I came up with this, through browsing the FirefoxProfile
code:
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
Which, as far as I have tested, has produced the expected behavior.
Hope this helps somebody!

- 1
- 1

- 11,900
- 22
- 62
- 102
-
Can anyone let me know how can I achieve this in PHP using Facebook webdriver? – Gohel Kiran Mar 28 '18 at 16:31
-
-
@juan carlos coto I am using a python selenium script. after clicking on a link it opens new window handle but error not resolved by above code – Vishav Gupta Mar 01 '21 at 07:35
No need of custom profiles to deal with "Untrusted connection" on WebDriver
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new FirefoxDriver(capabilities);

- 19,677
- 20
- 102
- 125
None of the above answers worked for me. I'm using: https://github.com/mozilla/geckodriver/releases/download/v0.12.0/geckodriver-v0.12.0-win64.zip
Firefox 50.1.0
Python 3.5.2
Selenium 3.0.2
Windows 10
I resolved it just by using a custom FF profile which was easier to do than I expected. Using this info https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager on how to make a custom profile, I did the following: 1) Made a new profile 2) Manually went to the site in FF to raise the untrusted certificate error 3) Add a site exception (when the error is raised click advanced and then add exception) 4) confirm the exception works by reloading the site (you should no longer get the error 5) Copy the newly create profile into your project (for me it's a selenium testing project) 6) Reference the new profile path in your code
I didn't find any of the following lines resolved the issue for me:
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['handleAlerts'] = True
firefox_capabilities['acceptSslCerts'] = True
firefox_capabilities['acceptInsecureCerts'] = True
profile = webdriver.FirefoxProfile()
profile.set_preference('network.http.use-cache', False)
profile.accept_untrusted_certs = True
But using a custom profile as mentioned above did. Here is my code:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
#In the next line I'm using a specific FireFox profile because
# I wanted to get around the sec_error_unknown_issuer problems with the new Firefox and Marionette driver
# I create a FireFox profile where I had already made an exception for the site I'm testing
# see https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager
ffProfilePath = 'D:\Work\PyTestFramework\FirefoxSeleniumProfile'
profile = webdriver.FirefoxProfile(profile_directory=ffProfilePath)
geckoPath = 'D:\Work\PyTestFramework\geckodriver.exe'
browser = webdriver.Firefox(firefox_profile=profile, capabilities=firefox_capabilities, executable_path=geckoPath)
browser.get('http://stackoverflow.com')

- 887
- 12
- 19
From start to finish with all the trimmings, in C#. Note that I had installed FFv48 to a custom directory because GeckoDriver requires that specific version.
var ffOptions = new FirefoxOptions();
ffOptions.BrowserExecutableLocation = @"C:\Program Files (x86)\Mozilla Firefox48\firefox.exe";
ffOptions.LogLevel = FirefoxDriverLogLevel.Default;
ffOptions.Profile = new FirefoxProfile { AcceptUntrustedCertificates = true };
var service = FirefoxDriverService.CreateDefaultService(ffPath, "geckodriver.exe");
var Browser = new FirefoxDriver(service, ffOptions, TimeSpan.FromSeconds(120));

- 4,347
- 27
- 39

- 1,802
- 1
- 17
- 23
-
1I also had to set `security.enterprise_roots.enabled`. My full startup: https://stackoverflow.com/a/62266190/1462295 – BurnsBA Jun 08 '20 at 15:57
In my case I was using Marionette driver instead of Firefox driver. There is an acknowledged bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1103196) for it. In the meantime I'm using Firefox driver instead:
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
dc.setCapability(FirefoxDriver.PROFILE, profile);
// this is the important line - i.e. don't use Marionette
dc.setCapability(FirefoxDriver.MARIONETTE, false);
Webdriver driver = new FirefoxDriver(dc);

- 21,349
- 5
- 54
- 89
-
This bug is now marked as fixed, can you suggest, how to use the fixed Marionette driver (I have downloaded the geckodriver.exe 0.11.1 which probably does not contain the fix yet). – Vojtěch Dohnal Nov 28 '16 at 14:00
C#: Something have changed as options now has own attribute for this.
var ffOptions = new FirefoxOptions();
ffOptions.AcceptInsecureCertificates = true;
Driver = new FirefoxDriver(ffOptions);
Hope this helps.

- 39
- 2
I added the below and then it worked for me
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);

- 59
- 1
- 4
-
This is Java, correct? Good to have alternatives in other languages! – Juan Carlos Coto Jun 10 '17 at 21:48
For Firefox driver
and Java
add these lines:
WebDriver driver;
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("default");
testprofile.setAcceptUntrustedCertificates(true);
testprofile.setAssumeUntrustedCertificateIssuer(true);
driver = new FirefoxDriver(testprofile);
If you use geckodriver
don't forget to add this before profile initialization:
System.setProperty("webdriver.gecko.driver","<PATH_TO_GECKODRIVER>\\geckodriver.exe");

- 7,577
- 10
- 44
- 82

- 1,086
- 12
- 16
For me, using PHP facebook/webdriver
I set create a profile and authorised the certified. The name of profile was selenium
.
Next I initialise my selenium 3:
java -jar -Dwebdriver.firefox.profile=selenium selenium-server-standalone-3.0.1.jar
Then in FirefoxDriver.php
I set const PROFILE = 'selenium';
This worked for me.

- 18,169
- 13
- 73
- 107

- 11
- 1
In Java you have to use DesiredCapabilities.setAcceptInsecureCerts()
. To get a FirefoxDriver with custom capability and profile do the following:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setAcceptInsecureCerts(true);
FirefoxProfile profile = new FirefoxProfile();
profile.set*...
FirefoxOptions options = new FirefoxOptions();
options.addCapabilities(capabilities);
options.setProfile(profile);
new FirefoxDriver(options);

- 3,650
- 5
- 30
- 41
In my case this did the trick
FirefoxOptions options = new FirefoxOptions();
options.addCapabilities(new ImmutableCapabilities(ImmutableMap.of(
CapabilityType.ACCEPT_SSL_CERTS, true,
CapabilityType.ACCEPT_INSECURE_CERTS, true)));
WebDriver driver = new FirefoxDriver(options);

- 978
- 2
- 10
- 28
Above solution worked for me on Firefox 54.0b9 (64-bit). This is my code.
- Create your capabilities
- Create FF Profile with your requirements
- Add 1. & 2. to Firefox Options and pass it to FirefoxDriver
Like below
capabilities = new DesiredCapabilities().firefox();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
//Accept Untrusted connection and to download files
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
profile.setPreference("dom.file.createInChild", true);
profile.setPreference("browser.download.folderList", 1);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.showWhenStarting"
,false);
profile.setPreference("pdfjs.disabled", true );
profile.setPreference("browser.helperApps.neverAsk.saveToDisk"
,"application/pdf;image/jpg;image/jpeg;text/html;text/plain;application/zip;application/download");
System.setProperty("webdriver.gecko.driver", config.getGeckoDriver());
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
FirefoxOptions options = new FirefoxOptions();
options.addCapabilities(capabilities);
options.setProfile(profile);
driver=new FirefoxDriver(options);

- 11,565
- 12
- 43
- 70
This configuration works for me in PHP
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowserUrl('https://example.loc');
$this->setBrowser('firefox');
$this->setDesiredCapabilities(["acceptInsecureCerts" => true]);
}
For Firefox I run
java -jar selenium-server-standalone-3.8.1.jar -enablePassThrough false

- 591
- 4
- 8
I was having this issue useing Node JS and Selenium. Searched everywhere but could not find anything.
Finally got it. Maybe this will help someone.
var webdriver = require('selenium-webdriver');
driver = new webdriver.Builder()
.withCapabilities({'browserName': 'firefox', acceptSslCerts: true, acceptInsecureCerts: true})
.build()

- 3,616
- 1
- 18
- 21
for PHP please use below code
$serverUrl = 'http://localhost:4444/wd/hub';
$capabilities = new DesiredCapabilities(
[
'browserName' => 'firefox',
'proxy' => [
'proxyType' => 'manual',
'httpProxy' => 'localhost:0000',
'sslProxy' => 'localhost:XXXX',
],
]
);
$capabilities->setCapability('acceptInsecureCerts',True);
$driver = RemoteWebDriver::create($serverUrl, $capabilities,60*1000,60*1000);

- 235
- 1
- 9