2

I am running the following but getting the error

public class base
{
    public static WebDriver driver;

    public static void main(String[]  args) throws MalformedURLException, InterruptedException
    {
        System.setProperty("webdriver.chrome.driver", "C:\\code\\lib\\browser drivers\\chromedriver.exe");

        String URL = "http://www.google.com";
        String Node = "http://localhost:4444/wd/hub";
        DesiredCapabilities cap = DesiredCapabilities.chrome();
        cap = DesiredCapabilities.chrome();
        cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);


        driver = new RemoteWebDriver(new URL(Node), cap);

        driver.navigate().to(URL);
        Thread.sleep(5000);
        driver.quit();
    }       
}

Error shown is as follows :

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'RAJESHW10', ip: '169.254.3.253', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: driver.version: unknown
Command duration or timeout: 316 milliseconds
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Can somebody please help

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Possible duplicate of [Unable to create new Chrome remote session](https://stackoverflow.com/questions/41600657/unable-to-create-new-chrome-remote-session) – Greg Rozmarynowycz Jan 02 '18 at 21:40

2 Answers2

0

The error does gives us a hint about what is going wrong as follows :

  • Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService : Unable to create new service: ChromeDriverService which means the new session wasn't initiated.
  • Driver info: driver.version: unknown : driver.version: unknown means the chromedriver binary wasn't invoked at all.
  • at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) : sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) which stems out from either of the following :

    java.lang.RuntimeException: exception in constructor : Occurance of this exception is unique to reflection. Normally, it is impossible to write code which ignores a checked exception as it would not compile at all.

    java.lang.reflect.InvocationTargetException : If an InvocationTargetException is thrown that means the method was invoked. This exception does not indicate a problem with the reflection package or its usage.

    java.lang.IllegalArgumentException : An IllegalArgumentException is thrown if the constructor was passed an argument of the wrong type.


Conclusion

From the above mentioned ponints it is pretty clear that the version of Selenium-Java client, JDK, ChromeDriver binary and Chrome are not compatible.


Solution

The solution would be as follows :

  • Update your JDK with the recent releases (JDK 8u152)
  • Update your Selenium-Java client with the recent releases (Selenium-Java v3.8.1)
  • Update your ChromeDriver binary with the recent releases (ChromeDriver v2.34)
  • Update your ChromeDriver binary with the recent releases (Chrome v63.0)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Please do the following and retry.

Ensure that the path C:\\code\\lib\\browser drivers\\chromedriver.exe is added to your %PATH% variable on the machine in which you are running the node. This would ensure that the selenium uber jar can find the location of the chromedriver binary.

System.setProperty("webdriver.chrome.driver", "C:\code\lib\browser drivers\chromedriver.exe");

This mechanism should be only used when you are doing

ChromeDriver driver = ChromeDriver()

Since you are working with a selenium grid, you are dealing with multiple JVMs here.

System.setProperty() will affect only the current JVM (which in this case is your tests), but the actual browser gets spun off in a different JVM (the one that is running the selenium node).

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66