6

So I have been trying to make a program that can interact with a webpage to input data. I ideally wanted to use Chrome so I tried to set up Selenium WebDriver and ChromeDriver.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Chrome {

public static void main(String[] args) {

    //Set chromedriver path
    System.setProperty("webdriver.chrome.driver","C:/Users/Username/Desktop/Comp Sci work/chromedriver.exe");

    WebDriver driver = new ChromeDriver();

     // Open Google
    driver.get("http://www.google.com");

    // Maximize browser
    driver.manage().window().maximize();

}
}

I seem to have set up the external JARs correctly as I can import them with no problem. The problem is for some reason the Chrome process cannot be created. I thought this might've been because there was already a Chrome process open but no. I still got the same error when I killed the process.

I then tried to set reset the path to Chrome, as the default one might've been different to mine, but still no luck.

public class Chrome {

public static void main(String[] args) {

    //Set chromedriver path
    System.setProperty("webdriver.chrome.driver","C:/Users/Username/Desktop/Comp Sci work/chromedriver.exe");

    ChromeOptions options = new ChromeOptions();
    options.setBinary("C:\\Users\\Username\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");

    WebDriver driver = new ChromeDriver();

     // Open Google
    driver.get("http://www.google.com");

    // Maximize browser
    driver.manage().window().maximize();

}
}

The error message is:

Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) 
on port 43997
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown 
error: Failed to create a Chrome process.
(Driver info: chromedriver=2.41.578737 
(49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 199 milliseconds
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08- 
02T20:05:20.749Z'

As the chromedriver seems to start fine the problem is simply in creating the chrome process but I can't seem to find out why. Any help would be appreciated(Also tips about my post formatting, as this is my first post). Thanks

Declan
  • 65
  • 1
  • 1
  • 5
  • Can you please specify chrome browser version? – Cryptex Technologies Aug 16 '18 at 11:41
  • Yes of course, my chrome is up to date as of the time i'm writing this. Version 68.0.3440.106 (64-bit). – Declan Aug 17 '18 at 12:42
  • I have the same problem!! – marti_ Aug 20 '18 at 01:35
  • https://stackoverflow.com/questions/38846079/only-local-connections-are-allowed-chrome-selenium-webdriver/42808127 – pburgr Aug 23 '18 at 09:21
  • Thank you for the link but it seems that thread addresses a different issue. My problem is that my WebDriver can't create a Chrome process. I've looked at any logs left behind but i can't seem to make any sense of them. I don't think the problem is in the server. – Declan Aug 29 '18 at 12:55
  • Did you find a solution? I have the same problem – Johannes Mols Sep 18 '18 at 08:34
  • No, unfortunately not, I'm now trying to make the program with Python and I seem to have gotten a bit further. @JohannesMols – Declan Sep 21 '18 at 08:39
  • I have this problem [too](https://stackoverflow.com/questions/53191422/webdriverexception-unknown-errors-chrome-failed-to-start-and-failed-to-crea). – Mate Mrše Nov 12 '18 at 12:22

2 Answers2

4

I meet this problem today,and solved it finally.it's because the chrome run as Administrator.so java can't start it.

Google Chrome Properties->Compatibility->not run as administrator

fly Lee
  • 56
  • 3
3

(for Mac) Change binary path from

/Applications/Google\ Chrome.app

..to:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Martin Janíček
  • 444
  • 1
  • 6
  • 13