Selenium 为什么将 acceptuntrustedcertificates 设置为 true 对于 firefox 驱动程序不起作用?
Selenium Why setting acceptuntrustedcertificates to true for firefox driver doesn't work?
我正在开发一些 selenium 测试,但我遇到了一个重要问题,因为当我使用安全连接 (HTTPS).我在 Whosebug 上找到的所有解决方案都已过时或不起作用:
- I am writing a Selenium script in Firefox but I am getting "Untrusted Certificate"
- How to disable Firefox's untrusted connection warning using Selenium?
- Handling UntrustedSSLcertificates using WebDriver
我唯一的解决方法是使用 github 上指示的夜间 mozilla 版本:https://github.com/mozilla/geckodriver/issues/420
private IWebDriver driver;
private string baseURL;
private FirefoxOptions ffOptions;
private IWait<IWebDriver> wait;
[SetUp]
public void SetupTest()
{
ffOptions = new FirefoxOptions();
ffOptions.BrowserExecutableLocation = @"D:\AppData\Local\Nightly\firefox.exe";
FirefoxProfile profile = new FirefoxProfile();
profile.AssumeUntrustedCertificateIssuer = false;
profile.AcceptUntrustedCertificates = true;
ffOptions.Profile = profile;
ffOptions.LogLevel = FirefoxDriverLogLevel.Info;
driver = new FirefoxDriver(FirefoxDriverService.CreateDefaultService(), ffOptions, TimeSpan.FromSeconds(30));
//[...]
}
配置:
- Firefox v47.0.1、v49.0.2、v51.0.1、v52.0b9(我尝试了这些不同的版本)
- 壁虎驱动 0.14
- 硒 3.1.0
有没有人有避免使用夜间发布的解决方案?
有关信息,由于我的互联网政策,我只能访问 Whosebug 和 github,请不要建议我使用 chrome!
感谢您的帮助!
是的,这是 geckodriver 上的一个错误。你可以找到它 here!
在 FirefoxOptions
中将 AcceptInsecureCertificates
属性 设置为 true
为我解决了这个问题。这是此更改后我的初始化的样子:
var profile = new FirefoxProfile();
profile.DeleteAfterUse = true;
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", LocalURL);
profile.SetPreference("network.automatic-ntlm-auth.allow-non-fqdn", true);
profile.SetPreference("webdriver_accept_untrusted_certs", true);
// Only setting this property to true did not work for me either
profile.AcceptUntrustedCertificates = true;
profile.AssumeUntrustedCertificateIssuer = false;
return new FirefoxDriver(new FirefoxOptions
{
Profile = profile,
// When I also added this line, it DID work
AcceptInsecureCertificates = true
});
我正在开发一些 selenium 测试,但我遇到了一个重要问题,因为当我使用安全连接 (HTTPS).我在 Whosebug 上找到的所有解决方案都已过时或不起作用:
- I am writing a Selenium script in Firefox but I am getting "Untrusted Certificate"
- How to disable Firefox's untrusted connection warning using Selenium?
- Handling UntrustedSSLcertificates using WebDriver
我唯一的解决方法是使用 github 上指示的夜间 mozilla 版本:https://github.com/mozilla/geckodriver/issues/420
private IWebDriver driver;
private string baseURL;
private FirefoxOptions ffOptions;
private IWait<IWebDriver> wait;
[SetUp]
public void SetupTest()
{
ffOptions = new FirefoxOptions();
ffOptions.BrowserExecutableLocation = @"D:\AppData\Local\Nightly\firefox.exe";
FirefoxProfile profile = new FirefoxProfile();
profile.AssumeUntrustedCertificateIssuer = false;
profile.AcceptUntrustedCertificates = true;
ffOptions.Profile = profile;
ffOptions.LogLevel = FirefoxDriverLogLevel.Info;
driver = new FirefoxDriver(FirefoxDriverService.CreateDefaultService(), ffOptions, TimeSpan.FromSeconds(30));
//[...]
}
配置:
- Firefox v47.0.1、v49.0.2、v51.0.1、v52.0b9(我尝试了这些不同的版本)
- 壁虎驱动 0.14
- 硒 3.1.0
有没有人有避免使用夜间发布的解决方案?
有关信息,由于我的互联网政策,我只能访问 Whosebug 和 github,请不要建议我使用 chrome!
感谢您的帮助!
是的,这是 geckodriver 上的一个错误。你可以找到它 here!
在 FirefoxOptions
中将 AcceptInsecureCertificates
属性 设置为 true
为我解决了这个问题。这是此更改后我的初始化的样子:
var profile = new FirefoxProfile();
profile.DeleteAfterUse = true;
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", LocalURL);
profile.SetPreference("network.automatic-ntlm-auth.allow-non-fqdn", true);
profile.SetPreference("webdriver_accept_untrusted_certs", true);
// Only setting this property to true did not work for me either
profile.AcceptUntrustedCertificates = true;
profile.AssumeUntrustedCertificateIssuer = false;
return new FirefoxDriver(new FirefoxOptions
{
Profile = profile,
// When I also added this line, it DID work
AcceptInsecureCertificates = true
});