ChromeDriver 仅打开具有有效 SSL 证书的网站

ChromeDriver opens sites only with valid SSL certs

同一个站点有两个实例,唯一的区别是,一个使用有效的,另一个使用无效的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

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/");

图片供参考

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

acceptInsecureCerts: true