如何使用Selenium禁用Firefox的不受信任的连接警告?

时间:2013-06-02 03:44:03

标签: firefox ssl selenium certificate ssl-certificate

尝试找到一种方法来禁止Firefox在每次连接使用“不受信任”证书时使用Selenium发出警告。我相信那种最有效的解决方案是设置一个浏览器首选项。

非常感谢!任何建议将不胜感激!

15 个答案:

答案 0 :(得分:16)

刚刚从Mozilla Foundation错误链接中找到了这个,它对我有用。

caps.setCapability("acceptInsecureCerts",true)

答案 1 :(得分:8)

我找到了this comment on enabling this functionality in Selenium for Java。还有this StackOverflow question about the same issue, also for Java对于Python,这是我想要的目标语言,我通过浏览FirefoxProfile代码来提出这个:

profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True

据我测试,这产生了预期的行为。

希望这有助于某人!

答案 2 :(得分:5)

无需自定义配置文件来处理WebDriver上的“不受信任的连接

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new FirefoxDriver(capabilities);

答案 3 :(得分:3)

从开始到结束所有的修剪,在C#中。请注意,我已将FFv48安装到自定义目录,因为GeckoDriver需要特定版本。

    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 :(得分:3)

上述答案都不适合我。我正在使用: 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

我只是通过使用比我预期更容易的自定义FF配置文件来解决它。使用此信息https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager了解如何制作自定义配置文件,我执行了以下操作: 1)制作了新的个人资料 2)手动转到FF中的站点以提高不受信任的证书错误 3)添加站点异常(当引发错误时单击advanced然后添加异常) 4)通过重新加载站点确认异常工作(您不应再收到错误 5)将新创建的配置文件复制到您的项目中(对我而言,这是一个硒测试项目) 6)在代码中引用新的配置文件路径

我没有发现以下任何一行为我解决了这个问题:

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

但是如上所述使用自定义配置文件。 这是我的代码:

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

答案 5 :(得分:2)

在我的情况下,我使用的是Marionette驱动程序而不是Firefox驱动程序。有一个公认的错误(https://bugzilla.mozilla.org/show_bug.cgi?id=1103196)。与此同时,我正在使用Firefox驱动程序:

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

答案 6 :(得分:2)

我添加了以下内容,然后它对我有用

CheckboxItem

答案 7 :(得分:1)

对于Firefox driverJava添加以下行:

WebDriver driver;
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("default");
testprofile.setAcceptUntrustedCertificates(true);
testprofile.setAssumeUntrustedCertificateIssuer(true);
driver = new FirefoxDriver(testprofile);

如果您使用geckodriver,请不要忘记在个人资料初始化之前添加此内容:

System.setProperty("webdriver.gecko.driver","<PATH_TO_GECKODRIVER>\\geckodriver.exe");

答案 8 :(得分:1)

对我来说,使用PHP facebook/webdriver我设置创建个人资料并授权认证。个人资料的名称为selenium

接下来我初始化了我的硒3:

java -jar -Dwebdriver.firefox.profile=selenium selenium-server-standalone-3.0.1.jar

然后在FirefoxDriver.php 我设置const PROFILE = 'selenium';

这对我有用。

答案 9 :(得分:1)

Java 中,您必须使用DesiredCapabilities.setAcceptInsecureCerts()。要获得具有自定义功能和配置文件的FirefoxDriver,请执行以下操作:

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

答案 10 :(得分:1)

在我看来,这很成功

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

答案 11 :(得分:1)

C#:某些更改,因为选项现在对此具有自己的属性。

var ffOptions = new FirefoxOptions();
ffOptions.AcceptInsecureCertificates = true;
Driver = new FirefoxDriver(ffOptions);

希望这会有所帮助。

答案 12 :(得分:0)

以上解决方案适用于Firefox 54.0b9(64位)。这是我的代码。

  1. 创建您的能力
  2. 根据您的要求创建FF个人资料
  3. 添加1.&amp; 2.到Firefox选项并将其传递给FirefoxDriver
  4. 如下所示

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

答案 13 :(得分:0)

此配置在PHP中对我有效

public function setUp()
{
    $this->setHost('localhost');
    $this->setPort(4444);
    $this->setBrowserUrl('https://example.loc');
    $this->setBrowser('firefox');
    $this->setDesiredCapabilities(["acceptInsecureCerts" => true]);
}

对于Firefox,我运行

java -jar selenium-server-standalone-3.8.1.jar -enablePassThrough false

答案 14 :(得分:0)

我在使用Node JS和Selenium时遇到了这个问题。在各处搜索,但找不到任何内容。

最后知道了。也许这会帮助某人。

var webdriver = require('selenium-webdriver');
driver = new webdriver.Builder()
.withCapabilities({'browserName': 'firefox', acceptSslCerts: true, acceptInsecureCerts: true})
.build()
相关问题