Skip to main content
1 of 2

Locate element is not working in Appium

I have located element for my App, and which is not working

My Code:

package tests;

import org.testng.annotations.Test; import java.net.MalformedURLException; import java.io.File; import java.net.URL; import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver;

public class AppiumTest { //static WebDriver driver; AppiumDriver driver;

public static void main(String[] args) throws InterruptedException, MalformedURLException {
    

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("automationName", "uiautomator 2");
    caps.setCapability("deviceName", "Andriod SDK built for x86");
    caps.setCapability("udid", "emulator-5554"); 
    caps.setCapability("platformName", "Android");
    caps.setCapability("platformVersion", "6.0");
    caps.setCapability("appPackage", "com.amazon.klite");
    caps.setCapability("appActivity", "com.amazon.klite.LoginActivity");
    caps.setCapability("noReset","true");
    caps.setCapability("autoGrantPermissions", true);
    

    try {
            AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
            Thread.sleep(5000);
        

    } catch (MalformedURLException e) {
        System.out.println(e.getMessage());
    }
}
@Test()

  public void Login()
  {
    driver.findElement(By.xpath("//android.widget.Button[@text='GET STARTED']"));
    //findElement(By.id("com.amazon.klite:id/activity_login_login_button")).click();
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//android.widget.EditText[@content-desc=\"Email (phone for mobile accounts)\"]")).sendKeys("[email protected]");
    
  }

}

Using above code I can Launch my App as Well,Further no action taking place

My Appium logs

[JSONWP Proxy] Got response with status 200: "{"sessionId":"2024b8c0-e9c4-4ced-948c-a994e74c799c","status":0,"value":{}}" [MJSONWP] Responding to client with driver.getSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appActivity":"com.amazon.klite.LoginActivity","appPackage":"com.amazon.klite","noReset":true,"platformVersion":"6.0","automationName":"uiautomator2","autoGrantPermissions":true,"platformName":"Android","udid":"emulator-5554","deviceName":"Andriod SDK built for x86"},"appActivity":"com.amazon.klite.LoginActivity","appPackage":"com.amazon.klite","noReset":true,"platformVersion":"6.0","automationName":"uiautomator2","autoGrantPermissions":true,"platformName":"Android","udid":"emulator-5554","deviceName":"emulator-5554","deviceUDID":"emulator-5554","deviceScreenSize":"480x800","deviceScreenDensity":240,"deviceModel":"Android SDK built for x86","deviceManufacturer":"unknown","deviceApiLevel":23,"pixelRatio":1.5,"statBarHeight":36,"viewportRect":{"left":0,"top":36,"width":480,"height":764}} [HTTP] <-- GET /wd/hub/session/6ef91da1-2db5-464b-adb4-8eb94a312e1c 200 23 ms - 1074 [HTTP] [BaseDriver] Shutting down because we waited 60 seconds for a command [UiAutomator2] Deleting UiAutomator2 session [UiAutomator2] Deleting UiAutomator2 server session [JSONWP Proxy] Proxying [DELETE /] to [DELETE http://localhost:8200/wd/hub/session/2024b8c0-e9c4-4ced-948c-a994e74c799c] with no body [BaseDriver] Shutting down because we waited 60 seconds for a command [UiAutomator2] Deleting UiAutomator2 session [Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability' [Appium] Removing session 92f9ba89-4f6c-443e-a808-be837e9e134d from our master session list [UiAutomator2] Deleting UiAutomator2 server session [JSONWP Proxy] Proxying [DELETE /] to [DELETE http://localhost:8200/wd/hub/session/2024b8c0-e9c4-4ced-948c-a994e74c799c] with no body [Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability' [Appium] Removing session 6ef91da1-2db5-464b-adb4-8eb94a312e1c from our master session list [JSONWP Proxy] Got response with status 200: "{"sessionId":"2024b8c0-e9c4-4ced-948c-a994e74c799c","status":0,"value":"Session deleted"}" [ADB] Running 'C:\Users\vaselvar\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am force-stop com.amazon.klite' [JSONWP Proxy] Got response with status 200: "{"sessionId":"2024b8c0-e9c4-4ced-948c-a994e74c799c","status":0,"value":"Session deleted"}" [ADB] Running 'C:\Users\vaselvar\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 shell am force-stop com.amazon.klite' [Logcat] Stopping logcat capture [ADB] Removing forwarded port socket connection: 8200 [ADB] Running 'C:\Users\vaselvar\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 forward --remove tcp:8200' [Logcat] Stopping logcat capture [ADB] Removing forwarded port socket connection: 8200 [ADB] Running 'C:\Users\vaselvar\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 forward --remove tcp:8200' [UiAutomator2] [UIAutomator2] [UiAutomator2] [UIAutomator2] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:. [UiAutomator2] [UIAutomator2] [UiAutomator2] [UIAutomator2] Time: 64.172 [UiAutomator2] [UIAutomator2] [UiAutomator2] [UIAutomator2] OK (1 test) [UiAutomator2] [UIAutomator2] [UiAutomator2] [UIAutomator2] [ADB] Running 'C:\Users\vaselvar\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 forward --remove tcp:8200' [UiAutomator2] Unable to remove port forward 'Error executing adbExec. Original error: 'Command 'C:\Users\vaselvar\AppData\Local\Android\sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 forward --remove tcp:8200' exited with code 1'; Stderr: 'error: listener 'tcp:8200' not found'; Code: '1''