在Chrome,IE和Opera上处理SSL证书的问题

时间:2016-06-14 12:32:35

标签: selenium ssl selenium-chromedriver operadriver

正如标题所说,我正在努力处理Chrome,IE和Opera浏览器中的SSL证书。 我在做什么:

ChromeOptions opt = new ChromeOptions();
opt.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);

IWebDriver driver = new ChromeDriver(opt);
driver.Navigate().GoToUrl("https://localhost");

我得到了什么:

Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
   at ...  (project name and path here)
Result Message: Initialization method <Project and test method name here> threw exception. System.InvalidOperationException: System.InvalidOperationException: unknown error: cannot parse capability: chromeOptions
from unknown error: unrecognized chrome option: acceptSslCerts
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64).

同样,我使用OperaOptionsOperaDriver类为Opera浏览器提供相同的功能:

System.InvalidOperationException: unknown error: cannot parse capability: operaOptions
from unknown error: unrecognized chrome option: acceptSslCerts

对于Internet Explorer浏览器,使用InternetExplorerOptionsInternetExplorerDriver类,我没有收到任何错误,但SSL证书处理不当。

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我假设您已经设置了chromedriver可执行属性。我建议你试试如下:

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new ChromeDriver(capability);