如何禁用Firefox';使用Selenium的不受信任连接警告?
试图找到一种方法来禁止Firefox在每次连接使用“不可信”证书时发出警告,使用Selenium。我相信最有效的解决方案是设置一个浏览器首选项。我发现。还有一个是Python,这是我想要的目标语言,我通过浏览如何禁用Firefox';使用Selenium的不受信任连接警告?,firefox,ssl,selenium,certificate,ssl-certificate,Firefox,Ssl,Selenium,Certificate,Ssl Certificate,试图找到一种方法来禁止Firefox在每次连接使用“不可信”证书时发出警告,使用Selenium。我相信最有效的解决方案是设置一个浏览器首选项。我发现。还有一个是Python,这是我想要的目标语言,我通过浏览FirefoxProfilecode: profile = webdriver.FirefoxProfile() profile.accept_untrusted_certs = True 据我所测试的,它已经产生了预期的行为 希望这对别人有帮助 无需自定义配置文件来处理WebDriver
FirefoxProfile
code:
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
据我所测试的,它已经产生了预期的行为
希望这对别人有帮助 无需自定义配置文件来处理WebDriver上的“不受信任的连接”
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new FirefoxDriver(capabilities);
从开始到结束,所有的装饰,用C。请注意,我已将FFv48安装到自定义目录,因为GeckoDriver需要该特定版本
var ffOptions=new FirefoxOptions();
ffOptions.BrowserExecutableLocation=@“C:\ProgramFiles(x86)\Mozilla Firefox48\firefox.exe”;
ffOptions.LogLevel=FirefoxDriverLogLevel.Default;
ffOptions.Profile=newfirefoxprofile{AcceptUntrustedCertificates=true};
var service=FirefoxDriverService.CreateDefaultService(ffPath,“geckodriver.exe”);
var Browser=新的FirefoxDriver(服务、F选项、TimeSpan.FromSeconds(120));
在我的例子中,我使用的是木偶驱动程序而不是Firefox驱动程序。它有一个公认的bug()。与此同时,我正在使用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);
以上所有答案对我都不起作用。我正在使用: 火狐50.1.0 Python 3.5.2 硒3.0.2 视窗10 我只是通过使用自定义FF配置文件解决了这个问题,这比我预期的要容易。使用这些关于如何创建自定义配置文件的信息,我执行了以下操作: 1) 制作了一个新的个人资料 2) 手动转到FF中的站点以引发不受信任的证书错误 3) 添加站点异常(出现错误时,单击“高级”,然后添加异常) 4) 通过重新加载站点(您不应该再收到错误)来确认异常有效 5) 将新创建的概要文件复制到您的项目中(对我来说,这是一个selenium测试项目) 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')
对于
Firefox驱动程序
和Java
添加以下行:
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");
System.setProperty(“webdriver.gecko.driver”,“\\geckodriver.exe”);
对于我来说,使用PHPfacebook/webdriver
我设置创建一个配置文件并授权认证的用户。配置文件的名称为selenium
接下来,我初始化selenium 3:
java -jar -Dwebdriver.firefox.profile=selenium selenium-server-standalone-3.0.1.jar
然后在FirefoxDriver.php中
我设置const PROFILE='selenium'代码>
<>这对我起作用。 < P>刚刚从Mozilla Foundation bug链接中找到这一点,它对我起作用。
caps.setCapability("acceptInsecureCerts",true)
我添加了下面的内容,然后它对我起了作用
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setAcceptInsecureCerts(true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
在Java中,您必须使用DesiredCapabilities.setAcceptSecureCerts()
。要获得具有自定义功能和配置文件的FirefoxDriver,请执行以下操作:
DesiredCapabilities=新的DesiredCapabilities();
setAcceptUnsecureCerts(true);
FirefoxProfile profile=新的FirefoxProfile();
profile.set*。。。
FirefoxOptions=新的FirefoxOptions();
选项。添加功能(功能);
选项。设置配置文件(配置文件);
新FirefoxDriver(可选);
上述解决方案在Firefox 54.0b9(64位)上对我有效。这是我的密码
创造你的能力
根据您的需求创建FF配置文件
加12.下载Firefox选项并将其传递给FirefoxDriver
如下
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);
就我而言,这就成功了
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);
这个配置在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
C#:由于选项现在具有自己的属性,某些内容已更改
var ffOptions = new FirefoxOptions();
ffOptions.AcceptInsecureCertificates = true;
Driver = new FirefoxDriver(ffOptions);
希望这有帮助。我在使用Node JS和Selenium时遇到了这个问题。到处找,但什么也没找到
终于明白了。也许这会对某人有所帮助
var webdriver = require('selenium-webdriver');
driver = new webdriver.Builder()
.withCapabilities({'browserName': 'firefox', acceptSslCerts: true, acceptInsecureCerts: true})
.build()
Firefox通常不显示证书错误屏幕。默认情况下,它在firefox和chrome中处理。只是IE没有处理。@JuanCarlosCoto为了解决这个问题,你还可以看看我关于希望这有帮助的回答……这个bug现在被标记为已修复,你能建议如何使用修复的木偶驱动程序(我已经下载了geckodriver.exe 0.11.1,它可能还没有包含修复)。我正在运行Selenium,通过wht nightwatch.js,这对我也很管用。(“AcceptSecureCerts”:true
)这是Java,对吗?很高兴有其他语言的替代品!有人能告诉我如何使用Facebook webdriver在PHP中实现这一点吗?知道如何在node js中实现吗?@juan carlos coto我使用的是python selenium脚本。点击一个链接后,它会打开新的窗口句柄,但上面代码未解决的错误选项似乎不再具有此功能。我还必须设置security.enterprise\u root.enabled
。我的全面启动: