How to disable Firefox's untrusted connection warning using Selenium?

57,114

Solution 1

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!

Solution 2

Just found this from the Mozilla Foundation bug link and it worked for me.

caps.setCapability("acceptInsecureCerts",true)

Solution 3

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);

Solution 4

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')

Solution 5

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));
Share:
57,114
Juan Carlos Coto
Author by

Juan Carlos Coto

Updated on October 08, 2021

Comments

  • Juan Carlos Coto
    Juan Carlos Coto over 2 years

    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.