Error SessionNotCreatedException with NativeConstructorAccessorImpl.newInstance0 while running selenium remotedriver

末鹿安然 提交于 2019-11-29 12:00:39

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)

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!