【问题标题】:ChromeDriver opens sites only with valid SSL certsChromeDriver 仅使用有效的 SSL 证书打开网站
【发布时间】:2023-03-31 03:36:02
【问题描述】:

同一个站点有两个实例,唯一的区别是,一个使用有效的,另一个使用无效的HTTPS/SSL certification。我尝试在无头ChromeDriver 2.31 中打开两者,发现它仅通过有效的SSL 认证打开站点。

<chromepath> --headless --remote-debugging-port=9101 --disable-gpu <siteurl>

上面的代码会打开一个站点https://chrome-devtools-frontend.appspot.com/serve_file/identification_number,其中包含来自给定站点的预览。

我用它来忽略证书问题,但我在ChromeDriver 中得到了这个站点的相同空白页。

caps.setCapability("chrome.switches", Arrays.asList("--ignore-certificate-errors"));

【问题讨论】:

  • DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ()handlSSLErr.setCapability(CapabilityType.ACCEPT_SSL_CERTS, false) 试试这个
  • @iamsankalp89 :我也尝试了值为 true 的代码,但它不起作用。
  • 好的,亲爱的,我们将尝试其他解决方案
  • @iamsankalp89 :我在调试过程中得到net::ERR_INSECURE_RESPONSE
  • 尝试更新的代码在我的电脑上运行

标签: ssl https webdriver ssl-certificate selenium-chromedriver


【解决方案1】:

你可以使用DesiredCapabilities

DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ();       
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, false);
WebDriver driver = new ChromeDriver (handlSSLErr);

试试吧,也许对你有帮助。

第二种方式:

System.setProperty("webdriver.chrome.driver", "E:\\software and tools\\chromedriver_win32\\chromedriver.exe");
ChromeOptions option= new ChromeOptions();
option.addArguments("headless");
option.addArguments("ignore-certificate-errors");
WebDriver d=new ChromeDriver(option);
//d.get("http://expired.badssl.com/");
d.get("https://expired.badssl.com/");

图片供参考

【讨论】:

  • 你能不能也试试无头模式?
  • 你能分享整个代码吗?在无头模式下它对我不起作用。
  • 问题仍然存在。它不适用于ERR_INSECURE_RESPONSE 错误。
【解决方案2】:

聚会迟到了,也许对某人有用,下面的参数对我有用。

acceptInsecureCerts: true

【讨论】:

  • 您能否建议 a) chrome 驱动程序版本 b) selenium 版本 c)chrome 浏览器版本的工作组合?我正在使用 Chrome 驱动程序版本:2.44,Selenium 版本:2.42,Chrome 浏览器版本 70.0。它在 selenium 中立即打开并释放连接(即关闭窗口)。在手册中,我收到错误,NET::ERR_CERT_COMMON_NAME_INVALID,能够通过接受警告访问!如果可能,请提供一段工作代码!
猜你喜欢
  • 2019-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-06
  • 2015-02-20
  • 2016-07-19
  • 1970-01-01
相关资源
最近更新 更多