Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Original error: Could not find a connected Android device.

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 2.32k
    Comment on it

    I tried to run the below piece code and getting the error Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created.

    public class TestCaller {
    
        public static AppiumDriver driver;
    
        public static void main(String[] args) throws MalformedURLException {
    
        DesiredCapabilities capabilites = new DesiredCapabilities();
    
        capabilites.setCapability("device", "Android");
        capabilites.setCapability("deviceName", "GT-N7100");
        capabilites.setCapability("platformVersion", "4.4.3");
        capabilites.setCapability("platformName", "Android");
    
        capabilites.setCapability("appPackage", "com.android.contacts");
        capabilites.setCapability("appActivity", "com.android.contacts.activities.PeopleActivity");
    
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilites);
            }
    }
    

    ERROR LOGS

    Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Could not find a connected Android device.) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 21.00 seconds Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33' System info: host: 'Admin-PC', ip: '172.18.0.142', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0' Driver info: io.appium.java_client.android.AndroidDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:176) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:107) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:40) at TestContactsNativeApp.main(TestContactsNativeApp.java:27)

    Solution

    Sometimes it may happen that if we don't perform any action on our mobile device then it gets disconnected automatically and in the system tray the mobile is displayed as connected. So, the best solution of this is to disconnect your mobile first and then connect it again.

 2 Comment(s)

  • If you have connected more than one Android devices then please make sure that the device on which you are running the script is present in the connected list. You should also remove the screen unlock functionality and then try to execute the script. If the device is connected but the screen is in locked state then in the connected devices list, the device goes in offline state and you will get the above error.

  • Dear Kaushik, I am getting the same error on my Windows 10 PC. Strange thing is that all android devices are getting enlisted on writing adb devices. I have tried adb kill-server and abd start-server but of no use.

    Can you please suggest a solution.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: