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

试图find一种方法来禁用Firefox提出警告,每次连接使用“不受信任”的证书,Selenium。 我相信那种最好的解决scheme是设置一个浏览器偏好。

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

我发现这个在Selenium for Java中启用这个function的评论 。 也有关于同样的问题的这个StackOverflow的问题,也为Java的 Python,这是我想要的目标语言,我想出了这个,通过浏览FirefoxProfile代码:

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

就我所testing的结果而言,它产生了预期的行为。

希望这有助于某人!

刚刚从Mozilla基金会的链接find这个,它为我工作。

 caps.setCapability("acceptInsecureCerts",true) 

WebDriver上不需要定制configuration文件来处理“ 不可信的连接

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

在我的情况下,我使用的是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 - ie don't use Marionette dc.setCapability(FirefoxDriver.MARIONETTE, false); Webdriver driver = new FirefoxDriver(dc); 

上面的答案都没有为我工作。 我正在使用: https : //github.com/mozilla/geckodriver/releases/download/v0.12.0/geckodriver-v0.12.0-win64.zip

Firefox 50.1.0

Python 3.5.2

selenium3.0.2

Windows 10

我只是通过使用自定义的FFconfiguration文件解决了这个问题,这比我预期的要容易得多。 使用此信息https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager关于如何制作自定义configuration文件,我做了如下:1)新build一个configuration文件2)手动到FF中的站点来提高不可信证书错误3)添加一个站点exception(当出现错误时点击高级,然后添加exception)4)确认exception工作重新加载站点(你不应该再得到错误5)将新创build的configuration文件复制到您的项目(对我来说,这是一个seleniumtesting项目)6)在代码中引用新的configuration文件path

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

 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 

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

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

我添加了下面,然后它为我工作

 DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setAcceptInsecureCerts(true); WebDriver driver = new FirefoxDriver(desiredCapabilities); 

从头到尾用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)); 

对于我来说,使用PHP的facebook/webdriver我设置创build一个configuration文件,并授权authentication。 configuration文件的名称是selenium

接下来我初始化我的selenium3:

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

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

这对我有效。

对于Firefox driverJava添加这些行:

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

如果你使用geckodriver ,不要忘记在configuration文件初始化之前添加这个:

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

Java中,你必须使用DesiredCapabilities.setAcceptInsecureCerts() 。 要获得具有自定义function和configuration文件的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);