Unable to login inside the webview content

I’m trying to run a Hybrid application through the Genymotion Emulator with Appium 1.3.4.1.

Started the appium server and eclipse.

Now the emulator is running but in eclipse console an error message is displayed :exclamation:

Randomly I am getting these four errors:

  1. A new session could not be created. (Original error: UiAutomator quit before it successfully launched)
  2. A new session could not be created. (Original error: Screen did not unlock)
  3. A new session could not be created. (Original error: Android device not found)
  4. A new session could not be created. (Original error: Activity used to start app doesn’t exist or cannot be launched! Make sure it exists and is a launchable activity)

Then I start the emulator manually and then I click the run button in eclipse.

By that time am not getting the above error message: It is going in to webview content but not able to find the element.

The error message is:

Exception in thread “main” org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15.45 seconds

Appium Settings:

Override Existing session = false

Here is my code

public static void main(String[] args) throws InterruptedException, ExecuteException, IOException {
        // TODO Auto-generated method stub
     
        String deviceName = "Google Nexus 5 - 4.4.4 - API 19 - 1080x1920";
     
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); 
        capabilities.setCapability("deviceName","Google Nexus 5 - 4.4.4 - API 19 - 1080x1920");    
        capabilities.setCapability("platformVersion", "4.4.4");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("app","D:/SOFTWARES/Apks/Hybrid.apk");

        **Starting the thirdy party genymotion emulator from the code.**

        DefaultExecutor executor = new DefaultExecutor();
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
     
        CommandLine launchEmul = new CommandLine("C:/Program Files/Genymobile/Genymotion/player");
        launchEmul.addArgument("--vm-name");
        launchEmul.addArgument("\""+deviceName+"\"");
        executor.setExitValue(1);
        executor.execute(launchEmul, resultHandler);
        Thread.sleep(40);
                
        driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
        System.out.println("SetUp is successful and Appium Driver is launched successfully");
        
        Login();
    }
    
    public static void Login() throws InterruptedException
    {   
     **Trying to do the login process in the Webview application**

    Set<String> contextNames = driver.getContextHandles();
        for (String contextName : contextNames) {
            System.out.println(contextName);
                        
          if (contextName.contains("WEBVIEW")){
             
              System.out.println("Application Loaded");
                           
             driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 
                
              driver.findElement(By.id("txtUserName")).clear();
              driver.findElement(By.id("txtUserName")).sendKeys("[email protected]");
                      
              driver.findElement(By.id("txtPassword")).clear();
              driver.findElement(By.id("txtPassword")).sendKeys("test1");
                      
              driver.findElement(By.id("btnLogin")).click();
          }
       }

The error is occuring when it is starting to find the txtUserName field

Before 3 days this same code worked very well. But now it is not working. I need some suggestions :confused: .

@SergeyTichomirov Can you help me over this

Hi @ashokkumarg!

Ok. I will try to help you :smile:
Let’s resolve the first problem!

I am suspecting that your Genymotion settings have to be changed. Please check your ADB settings:
1.

You have to specify the file path where Android SDK is installed.

@SergeyTichomirov Thank you very much. I have tried with the following settings.

But still the issue is there.
1.

Ok. Lets go forward
I think there is no need to use this code fragment is you’ve set up the path to Android SDK:

The code below works for me:

 capabilities.setCapability("deviceName","Android Emulator");    //!!! Please pay attention
    capabilities.setCapability("platformVersion", "4.4.4");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("app", YouPathToApk);
    ....
    //other actions

Please try it.

I too have done the same thing, which you mentioned above.

capabilities.setCapability("deviceName","Google Nexus 5 - 4.4.4 - API 19 - 1080x1920");    
capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app","D:/SOFTWARES/Apks/Hybrid.apk");

        DefaultExecutor executor = new DefaultExecutor();
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
        
        //The Genymotion emulator path
        CommandLine launchEmul = new CommandLine("C:/Program Files/Genymobile/Genymotion/player");
        launchEmul.addArgument("--vm-name");
        launchEmul.addArgument("\""+deviceName+"\"");
        executor.setExitValue(1);
        executor.execute(launchEmul, resultHandler);
        Thread.sleep(40);

        driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
        System.out.println("SetUp is successful and Appium Driver is launched successfully");

But still the same issue.

Are you starting your Genymotion from appium launch AVD or through code.
If you are starting it from appium can you post the settings.

I couldn’t able to start the Emulator through the code.
But if I start the emulator manually, it fails to find the webview elements.

@SergeyTichomirov Waiting for your reply