Selenium 和 SSL 证书中的 Chromedriver
我正在使用 Selenium 来测试一个具有 HTTP Auth 甚至 SSL 证书的网站。
作为 HTTP 基本身份验证的解决方法,我使用 ChromeDriver - http://code.google.com/ p/selenium/wiki/ChromeDriver 并以格式打开 URL
https://username:[email protected]
但现在出于安全原因,需要在 PC 上安装客户端证书才能登录该应用程序。
但是,ChromeDriver 看不到“选择证书”提示,我什至无法将其切换为警报。
有人解决这个问题了吗?
I am using Selenium to test a web site which has HTTP Auth and now even SSL certificate.
As workaround for HTTP Basic Authentification I am using ChromeDriver - http://code.google.com/p/selenium/wiki/ChromeDriver and opening URLs in format
https://username:[email protected]
But now from security reasons, Client certificate needs to be installed on PC in order to log into that application.
However, ChromeDriver cannot see the "select certificate" prompt and I even cannot switch to it as Alert.
Did somebody solved this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过添加包含以下内容的注册表密钥来告诉 Chrome 浏览器对特定 URL 使用特定客户端证书:
您可以通过在同一分支下添加其他密钥来添加其他条目。
在 Linux 上这有点复杂,因为您需要修改以下位置下 json 格式的首选项:
看起来上述选项仅适用于加入 Active Directory 域的计算机。如果上述步骤不起作用,您可以尝试使用预配置的模板来引入可从以下网址下载的更改: https://www.chromium.org/administrators/policy-templates
You can tell the Chrome browser to use a specific client certificate for a particual URL by adding a registry KEY with the following content:
You may add additional entries by adding additional keys under the same branch.
It's a little more complex on Linux as you need to modify the preferences which are in json format under the following location:
It looks like the above option only works for machines joined to an Active Directory domain. In case the above steps don't work You may try using a preconfigured template to introduce the changes available for download from the following url: https://www.chromium.org/administrators/policy-templates
您可以使用
--ignore-certificate-errors
命令行开关告诉 Chrome 忽略不受信任的证书错误,而不是安装客户端证书。为此,请创建
ChromeDriver
实例,如下所示:Instead of installing the Client Certificate you could just tell Chrome to ignore the untrusted certificate error using the
--ignore-certificate-errors
command line switch.To do this, create your instance of
ChromeDriver
as follows:我用下面的代码解决了这个问题
,但我必须使用下面的命令将我的 pfx 证书转换为 pem
I solved this issue with below code
But I had to convert my pfx certificate to pem using below command
为了以 Manvi 的答案为基础,我无法使用 PEM 证书或 PFX 证书使其工作,因此我必须使用 openssl 从我的 PFX 文件中手动提取证书和密钥
提取证书
提取密钥
代码
To build upon Manvi's answer, I could not get it working using a PEM certificate nor a PFX certificate, so I had to manually extract the certificate and key from my PFX file using openssl
Extract the certificate
Extract the key
Code