Jua*_*oto 21 ssl firefox selenium certificate ssl-certificate
试图找到一种方法来禁止Firefox在每次连接使用"不受信任"证书时使用Selenium发出警告.我相信那种最有效的解决方案是设置一个浏览器首选项.
非常感谢!任何建议将不胜感激!
小智 17
刚刚从Mozilla Foundation的bug链接中找到了它,它对我有用.
caps.setCapability("acceptInsecureCerts",true)
Run Code Online (Sandbox Code Playgroud)
我在Selenium for Java中找到了关于启用此功能的评论.还有关于同样问题的StackOverflow问题,也适用于Java For Python,这是我想要的目标语言,我通过浏览FirefoxProfile
代码得出了这个:
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
Run Code Online (Sandbox Code Playgroud)
据我测试,这已经产生了预期的行为.
希望这有助于某人!
无需自定义配置文件来处理WebDriver上的" 不受信任的连接 "
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new FirefoxDriver(capabilities);
Run Code Online (Sandbox Code Playgroud)
上述答案都不适合我。我正在使用: https://github.com/mozilla/geckodriver/releases/download/v0.12.0/geckodriver-v0.12.0-win64.zip
火狐50.1.0
Python 3.5.2
硒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) 添加站点例外(引发错误时单击高级,然后添加例外) 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
Run Code Online (Sandbox Code Playgroud)
但使用上面提到的自定义配置文件却可以。这是我的代码:
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')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
43726 次 |
最近记录: |