Nightwatch与自签名证书:Geckodriver不兼容acceptSslCerts配置?
解决方案:Geckodriver 忽略自签名 SSL 证书的正确配置
这个问题其实是Geckodriver(Marionette)和 Chromedriver 在证书信任参数上的差异导致的,并非你的配置错误,也不是 Nightwatch/Selenium 的兼容问题。
核心原因
Chromedriver 支持 acceptSslCerts 参数来忽略无效证书,但 Geckodriver(配合 Marionette 使用时)并不识别这个参数——它对应的正确参数是 acceptInsecureCerts。这是因为 Marionette 作为 Firefox 的新一代驱动,使用了和旧版 FirefoxDriver 不同的参数规范。
修改后的正确配置
把你 desiredCapabilities 里的 acceptSslCerts 替换成 acceptInsecureCerts 即可,修改后的配置如下:
"firefox": { "launch_url": "...", "selenium_port": 4444, "selenium_host": "localhost", "silent": true, ... "desiredCapabilities": { "browserName": "gecko", "marionette": true, "acceptInsecureCerts": true } }
额外说明
- 你使用的 Selenium 3.8.1 和最新版 Geckodriver 完全支持
acceptInsecureCerts参数,这是官方明确规定的标准参数。 - 如果修改后仍然有证书相关问题,可以尝试通过
firefoxOptions添加 Firefox 原生偏好设置来增强信任,比如:
不过大部分情况下,仅设置"desiredCapabilities": { "browserName": "gecko", "marionette": true, "acceptInsecureCerts": true, "moz:firefoxOptions": { "prefs": { "security.insecure_field_warning.contextual.enabled": false, "security.enterprise_roots.enabled": true } } }acceptInsecureCerts: true就足以解决自签名证书的问题。
内容的提问来源于stack exchange,提问作者Patrick
相关产品推荐
相关产品推荐

