英文:
ChromeDriver ERR_SSL_PROTOCOL_ERROR despite --allow-insecure-localhost
问题
我有一些使用ChromeDriver进行Selenium测试的代码,我正在使用ChromeDriver访问https://localhost:<port>
。在这种情况下,端口号使用自签名证书来支持HTTPS连接。
然而,当ChromeDriver打开并尝试导航到该本地地址时,Chrome会显示一个错误页面,错误为ERR_SSL_PROTOCOL_ERROR,如下面的截屏所示。
我进行了一些研究,并发现可以在WebDriver实例的capabilities对象中添加开关--allow-insecure-localhost
和--ignore-certificate-errors
。这个问题/答案给了我一些想法。我创建capabilities的代码如下:
ChromeOptions options = new ChromeOptions();
// 其他capabilities在这里
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
options.addArguments("--allow-insecure-localhost", "--ignore-certificate-errors");
尽管如此,当ChromeDriver实例尝试导航到本地主机时,我仍然会得到相同的错误页面。
我正在使用ChromeDriver 84.0.4147.30和Google Chrome版本84.0.4147.89
我该如何解决这个问题?
英文:
I have Selenium tests where I'm using ChromeDriver to go to https://localhost:<port>
. The port number in this case is using a self-signed certificate to support HTTPS connection.
However, when ChromeDriver opens and tries to navigate to that localhost address, Chrome gives an error screen ERR_SSL_PROTOCOL_ERROR as seen in screenshot below.
I did some research and found that adding the switches --allow-insecure-localhost
and --ignore-certificate-errors
to the capabilities object for the WebDriver instance. This question/answer gave me some ideas. My code for creating the capabilities is:
ChromeOptions options = new ChromeOptions();
// Other capabilities here
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
options.addArguments("--allow-insecure-localhost", "--ignore-certificate-errors");
Nonetheless, I still get the same error screen when the ChromeDriver instance tries to navigate to localhost.
I'm using ChromeDriver 84.0.4147.30 and Google Chrome Version 84.0.4147.89
How do I resolve this issue?
专注分享java语言的经验与见解,让所有开发者获益!
评论