When trying to run a Headless Chrome in Selenium, I followed this example, and wrote this code:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
driver = new ChromeDriver(chromeOptions);
But when running the code I got this error:
The path to the driver executable must be set by the webdriver.chrome.driver system property
So I added this to the code:
chromeOptions.setBinary(System.getProperty("webdriver.chrome.driver"));
And I send the parameter to the programs:
webdriver.chrome.driver=C:\\chromedriver_win32\\chromedriver.exe
But then I got this:
Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) on port 47772
Only local connections are allowed.
Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) on port 9515
Only local connections are allowed.
Invalid --log-level value.
Unable to initialize logging. Exiting...
So I added logging settings:
System.setProperty("webdriver.chrome.logfile", "C:\\chromedriver_win32\\chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
chromeOptions.setCapability("--log-level", "WARNING");
But that doesn't seem to help as the error is:
Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) on port 43365
Only local connections are allowed.
Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) on port 9515
Only local connections are allowed.
Invalid --log-level value.
Unable to initialize logging. Exiting...
Caused by: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: was killed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\\chromedriver_win32\\chromedriver.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
So it seems like the current problem is unknown error: DevToolsActivePort file doesn't exist