Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

java - Error SessionNotCreatedException with NativeConstructorAccessorImpl.newInstance0 while running selenium remotedriver

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...