1

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

riorio
  • 6,500
  • 7
  • 47
  • 100
  • 3
    I had a similar situation. The "unknown error: DevToolsActivePort file doesn't exist" problem is too generic, and only indicates that selenium can't start the process (or find the running driver). I believe that your problem (as it was with me) is the binary setting "chromeOptions.setBinary(System.getProperty("webdriver.chrome.driver"));" The setBinary is to indicate chrome.exe, not the chromedriver.exe, that's why you see two instances initiating. In Java you only need to set "webdriver.chrome.driver" env property so that chromedrive can be found – dchang Dec 07 '18 at 16:40

1 Answers1

0

To set the location of webdriver you can use this

System.setProperty("webdriver.chrome.driver","location-driver"); //before 'new ChromeDriver...'

To run it headless is what you tried

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
driver = new ChromeDriver(chromeOptions);
KunLun
  • 3,109
  • 3
  • 18
  • 65