Reputation: 5671
I use WebDriver
3.12. I have two instances from application, one with invalid and one with valid SSL certification. Testsuite is working correctly with one of valid certificate. --ignore-certificate-errors
flag is ignored in headless mode in ChromeDriver
2.40. I tried --acceptInsecureCerts
flag too, but has same effect.
I initialize driver variable as follows:
WebDriver driver = new ChromeDriver(new ChromeOptions().setExperimentalOption("prefs", prefs).addArguments("--start-maximized").addArguments("--acceptInsecureCerts").setHeadless(true));
Upvotes: 1
Views: 3904
Reputation: 5637
You can try this code snippet, which works for me:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("--headless", "--window-size=1920,1200","--ignore-certificate-errors");
DesiredCapabilities crcapabilities = DesiredCapabilities.chrome();
crcapabilities.setCapability(ChromeOptions.CAPABILITY, options);
crcapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
crcapabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "C:\\Path\\TO\\chromedriver.log");
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "C:\\Path\\TO\\chromedriver.exe");
ChromeDriverService service = null;
try {
service = new ChromeDriverService.Builder()
.usingAnyFreePort()
.withVerbose(true)
.build();
service.start();
} catch (IOException e) {
e.printStackTrace();
}
RemoteWebDriver driver = new RemoteWebDriver(service.getUrl(),crcapabilities);
driver.get("https://self-signed.badssl.com/");
System.out.println(driver.getPageSource());
driver.quit();
Output:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="/icons/favicon-red.ico" />
<link rel="apple-touch-icon" href="/icons/icon-red.png" />
<title>self-signed.badssl.com</title>
<link rel="stylesheet" href="/style.css" />
<style>body { background: red; }</style>
</head>
<body>
<div id="content">
<h1 style="font-size: 12vw;">
self-signed.<br />badssl.com
</h1>
</div>
</body></html>
Note: you have to add some imports:
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.io.IOException;
Upvotes: 1
Reputation: 3927
try setAcceptInsecureCerts. See java doc here for further info https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html#setAcceptInsecureCerts-boolean-
Upvotes: 3