2017-09-04 132 views
7

同一网站有两个实例,唯一不同的是,一个使用有效,另一个使用无效HTTPS/SSL certification。我试图在无头ChromeDriver 2.31中打开它,并发现它仅在有效的SSL认证中打开网站。ChromeDriver仅通过有效的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")); 
+0

DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome() handlSSLErr.setCapability(CapabilityType.ACCEPT_SSL_CERTS,FALSE)试试这个 – iamsankalp89

+0

@ iamsankalp89:我想你的代码价值也是真的,但它不起作用。 – plaidshirt

+0

好的,我们将尝试其他解决方案 – iamsankalp89

回答

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

图像仅供参考enter image description here

+0

再次出现同样的错误。这里是一个测试网站:https://expired.badssl.com。 – plaidshirt

+0

你可以在无头模式下试试吗? – plaidshirt

+0

也在无头模式下工作 – iamsankalp89