Appium server is returning true for clicking an element, but on real device the click never happens

I have an android app.When I run my script, the appium server returns true for finding the element and clicking on it.
But in actual, the click never happens.
I have set the automationName to “uiautomator2” and also the element i am trying to find has a unique xpath.

This is the code-

package AndroidTests;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;

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

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.interactions.internal.TouchAction;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;

public class LoginEmail {

   AndroidDriver driver=null;

 

 @BeforeClass

 public void setUp() throws Exception {

 
//location of the app

 File app = new File("C:\\Users\\HP\\Downloads", "android-debug.apk");



 DesiredCapabilities capability = new DesiredCapabilities();


 capability.setCapability("device","Android");

 capability.setCapability(CapabilityType.BROWSER_NAME, "");

 capability.setCapability(CapabilityType.VERSION, "5.1");

 capability.setCapability("app", app.getAbsolutePath());

 capability.setCapability("deviceName","69TWLVHA4SOFAMT8");

 capability.setCapability("platformName","Android");

 capability.setCapability("automationName","uiautomator2");
 capability.setCapability("app-package", "com.rapidue.uzed");

 capability.setCapability("app-activity", "com.rapidue.uzed.MainActivity");

 driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),capability);

 }

 

 @Test

public void Loginwithemail() throws MalformedURLException, InterruptedException{
	 
		System.out.println("App launched");
		Thread.sleep(20000);
		for(int i=1;i<4;i++)
		{
		 Dimension dim=driver.manage().window().getSize();
		int height = dim.getHeight();
		int width = dim.getWidth();
		int y = (int)(height*0.20);
		int startx = (int)(width*0.80);
		int endx = (int)(width*0.20);
		long l=1000;
		Duration d=Duration.ofMillis(1000);
		TouchAction a=new TouchAction((PerformsTouchActions) driver);
		
		a.press(startx,y).waitAction(d).moveTo(endx, y).release().perform();

		}
		Thread.sleep(5000);
		WebDriverWait wait=new WebDriverWait(driver, 10);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	WebElement b=driver.findElement(By.xpath("//android.widget.Button[@text='Get Started ']"));
b.click();
		Thread.sleep(5000);
		System.out.println("Signup page");
		 List<MobileElement> links=driver.findElements(By.xpath("//android.view.View[@index='2']"));
		 links.get(1).click();

}

This is the appium log-
ADB] 1 device(s) connected
[ADB] Running ‘C:\Users\HP\AppData\Local\Android\sdk\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“69TWLVHA4SOFAMT8”,“shell”,“dumpsys”,“window”,“windows”]
[ADB] Found package: ‘com.rapidue.uzed’ and fully qualified activity name : ‘com.rapidue.uzed.MainActivity’
[Appium] New AndroidUiautomator2Driver session created successfully, session e1f257ef-4a7d-426b-82d3-b9df5eb71eb8 added to master session list
[BaseDriver] Event ‘newSessionStarted’ logged at 1517901366304 (12:46:06 GMT+0530 (India Standard Time))
[MJSONWP] Responding to client with driver.createSession() result: {“app”:“C:\Users\HP\Downloads\android-debug.apk”,“app-activity”:“com.rapidue.uzed.MainActivity”,“app-package”:“com.rapidue.uzed”,“automationName”:“uiautomator2”,“browserName”:"",“device”:“Android”,“deviceName”:“69TWLVHA4SOFAMT8”,“platformName”:“android”,“version”:“5.1”}
[HTTP] <-- POST /wd/hub/session 200 26943 ms - 346
[HTTP] --> GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8 {}
[MJSONWP] Calling AppiumDriver.getSession() with args: [“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[MJSONWP] Responding to client with driver.getSession() result: {“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“app”:“C:\Users\HP\Downloads\android-debug.apk”,“app-activity”:“com.rapidue.uzed.MainActivity”,“app-package”:“com.rapidue.uzed”,“automationName”:“uiautomator2”,“browserName”:"",“device”:“Android”,“deviceName”:“69TWLVHA4SOFAMT8”,“platformName”:“android”,“version”:“5.1”},“app”:“C:\Users\HP\Downloads\android-debug.apk”,“app-activity”:“com.rapidue.uzed.MainActivity”,“app-package”:“com.rapidue.uzed”,“automationName”:“uiautomator2”,“browserName”:"",“device”:“Android”,“deviceName”:“69TWLVHA4SOFAMT8”,“platformName”:“android”,“version”:“5.1”,“deviceUDID”:“69TWLVHA4SOFAMT8”,“platformVersion”:“5.1”,“deviceScreenSize”:“720x1280”,“deviceScreenDensity”:320,“deviceModel”:“Lenovo P1ma40”,“deviceManufacturer”:“LENOVO”,“appPackage”:“com.rapidue.uzed”}
[HTTP] <-- GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8 200 3 ms - 1029
[HTTP] --> GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8 {}
[MJSONWP] Calling AppiumDriver.getSession() with args: [“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[MJSONWP] Responding to client with driver.getSession() result: {“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“app”:“C:\Users\HP\Downloads\android-debug.apk”,“app-activity”:“com.rapidue.uzed.MainActivity”,“app-package”:“com.rapidue.uzed”,“automationName”:“uiautomator2”,“browserName”:"",“device”:“Android”,“deviceName”:“69TWLVHA4SOFAMT8”,“platformName”:“android”,“version”:“5.1”},“app”:“C:\Users\HP\Downloads\android-debug.apk”,“app-activity”:“com.rapidue.uzed.MainActivity”,“app-package”:“com.rapidue.uzed”,“automationName”:“uiautomator2”,“browserName”:"",“device”:“Android”,“deviceName”:“69TWLVHA4SOFAMT8”,“platformName”:“android”,“version”:“5.1”,“deviceUDID”:“69TWLVHA4SOFAMT8”,“platformVersion”:“5.1”,“deviceScreenSize”:“720x1280”,“deviceScreenDensity”:320,“deviceModel”:“Lenovo P1ma40”,“deviceManufacturer”:“LENOVO”,“appPackage”:“com.rapidue.uzed”}
[HTTP] <-- GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8 200 2 ms - 1029
[HTTP] --> GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size {}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size] to [GET http://localhost:8201/wd/hub/session/19eb6a10-fb21-4fd4-a9e5-096313bf43ce/window/current/size] with body: {}
[JSONWP Proxy] Got response with status 200: “{“sessionId”:“19eb6a10-fb21-4fd4-a9e5-096313bf43ce”,“status”:0,“value”:{“height”:1280,“width”:720}}”
[JSONWP Proxy] Replacing sessionId 19eb6a10-fb21-4fd4-a9e5-096313bf43ce with e1f257ef-4a7d-426b-82d3-b9df5eb71eb8
[HTTP] <-- GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size 200 45 ms - 99
[HTTP] --> POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/touch/perform {“actions”:[{“action”:“press”,“options”:{“x”:576,“y”:256}},{“action”:“wait”,“options”:{“ms”:1000}},{“action”:“moveTo”,“options”:{“x”:144,“y”:256}},{“action”:“release”,“options”:{}}]}
[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{“action”:“press”,“options”:{“x”:576,“y”:256}},{“action”:“wait”,“options”:{“ms”:1000}},{“action”:“moveTo”,“options”:{“x”:144,“y”:256}},{“action”:“release”,“options”:{}}],“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[JSONWP Proxy] Proxying [POST /touch/perform] to [POST http://localhost:8201/wd/hub/session/19eb6a10-fb21-4fd4-a9e5-096313bf43ce/touch/perform] with body: {“startX”:576,“startY”:256,“endX”:144,“endY”:256,“steps”:28}
[JSONWP Proxy] Got response with status 200: {“sessionId”:“19eb6a10-fb21-4fd4-a9e5-096313bf43ce”,“status”:0,“value”:true}
[MJSONWP] Responding to client with driver.performTouch() result: true
[HTTP] <-- POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/touch/perform 200 553 ms - 76
[HTTP] --> GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size {}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size] to [GET http://localhost:8201/wd/hub/session/19eb6a10-fb21-4fd4-a9e5-096313bf43ce/window/current/size] with body: {}
[JSONWP Proxy] Got response with status 200: “{“sessionId”:“19eb6a10-fb21-4fd4-a9e5-096313bf43ce”,“status”:0,“value”:{“height”:1280,“width”:720}}”
[JSONWP Proxy] Replacing sessionId 19eb6a10-fb21-4fd4-a9e5-096313bf43ce with e1f257ef-4a7d-426b-82d3-b9df5eb71eb8
[HTTP] <-- GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size 200 26 ms - 99
[HTTP] --> POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/touch/perform {“actions”:[{“action”:“press”,“options”:{“x”:576,“y”:256}},{“action”:“wait”,“options”:{“ms”:1000}},{“action”:“moveTo”,“options”:{“x”:144,“y”:256}},{“action”:“release”,“options”:{}}]}
[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{“action”:“press”,“options”:{“x”:576,“y”:256}},{“action”:“wait”,“options”:{“ms”:1000}},{“action”:“moveTo”,“options”:{“x”:144,“y”:256}},{“action”:“release”,“options”:{}}],“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[JSONWP Proxy] Proxying [POST /touch/perform] to [POST http://localhost:8201/wd/hub/session/19eb6a10-fb21-4fd4-a9e5-096313bf43ce/touch/perform] with body: {“startX”:576,“startY”:256,“endX”:144,“endY”:256,“steps”:28}
[JSONWP Proxy] Got response with status 200: {“sessionId”:“19eb6a10-fb21-4fd4-a9e5-096313bf43ce”,“status”:0,“value”:true}
[MJSONWP] Responding to client with driver.performTouch() result: true
[HTTP] <-- POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/touch/perform 200 628 ms - 76
[HTTP] --> GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size {}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size] to [GET http://localhost:8201/wd/hub/session/19eb6a10-fb21-4fd4-a9e5-096313bf43ce/window/current/size] with body: {}
[JSONWP Proxy] Got response with status 200: “{“sessionId”:“19eb6a10-fb21-4fd4-a9e5-096313bf43ce”,“status”:0,“value”:{“height”:1280,“width”:720}}”
[JSONWP Proxy] Replacing sessionId 19eb6a10-fb21-4fd4-a9e5-096313bf43ce with e1f257ef-4a7d-426b-82d3-b9df5eb71eb8
[HTTP] <-- GET /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/window/current/size 200 25 ms - 99
[HTTP] --> POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/touch/perform {“actions”:[{“action”:“press”,“options”:{“x”:576,“y”:256}},{“action”:“wait”,“options”:{“ms”:1000}},{“action”:“moveTo”,“options”:{“x”:144,“y”:256}},{“action”:“release”,“options”:{}}]}
[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{“action”:“press”,“options”:{“x”:576,“y”:256}},{“action”:“wait”,“options”:{“ms”:1000}},{“action”:“moveTo”,“options”:{“x”:144,“y”:256}},{“action”:“release”,“options”:{}}],“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[JSONWP Proxy] Proxying [POST /touch/perform] to [POST http://localhost:8201/wd/hub/session/19eb6a10-fb21-4fd4-a9e5-096313bf43ce/touch/perform] with body: {“startX”:576,“startY”:256,“endX”:144,“endY”:256,“steps”:28}
[JSONWP Proxy] Got response with status 200: {“sessionId”:“19eb6a10-fb21-4fd4-a9e5-096313bf43ce”,“status”:0,“value”:true}
[MJSONWP] Responding to client with driver.performTouch() result: true
[HTTP] <-- POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/touch/perform 200 646 ms - 76
[HTTP] --> POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/timeouts {“type”:“implicit”,“ms”:30000}
[MJSONWP] Calling AppiumDriver.timeouts() with args: [“implicit”,30000,“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[BaseDriver] Set implicit wait to 30000ms
[MJSONWP] Responding to client with driver.timeouts() result: null
[HTTP] <-- POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/timeouts 200 8 ms - 76
[HTTP] --> POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/element {“using”:“xpath”,“value”:"//android.widget.Button[@text='Get Started ']"}
[MJSONWP] Calling AppiumDriver.findElement() with args: [“xpath”,"//android.widget.Button[@text='Get Started ']",“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 30000 ms for condition
[JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8201/wd/hub/session/19eb6a10-fb21-4fd4-a9e5-096313bf43ce/element] with body: {“strategy”:“xpath”,“selector”:"//android.widget.Button[@text='Get Started ']",“context”:"",“multiple”:false}
[JSONWP Proxy] Got response with status 200: {“sessionId”:“19eb6a10-fb21-4fd4-a9e5-096313bf43ce”,“status”:0,“value”:{“ELEMENT”:“ec6d74a7-202b-4b67-9da8-64588d206e38”}}
[MJSONWP] Responding to client with driver.findElement() result: {“ELEMENT”:“ec6d74a7-202b-4b67-9da8-64588d206e38”}
[HTTP] <-- POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/element 200 1447 ms - 122
[HTTP] --> POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/element/ec6d74a7-202b-4b67-9da8-64588d206e38/click {“id”:“ec6d74a7-202b-4b67-9da8-64588d206e38”}
[MJSONWP] Calling AppiumDriver.click() with args: [“ec6d74a7-202b-4b67-9da8-64588d206e38”,“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[JSONWP Proxy] Proxying [POST /element/ec6d74a7-202b-4b67-9da8-64588d206e38/click] to [POST http://localhost:8201/wd/hub/session/19eb6a10-fb21-4fd4-a9e5-096313bf43ce/element/ec6d74a7-202b-4b67-9da8-64588d206e38/click] with body: {“element”:“ec6d74a7-202b-4b67-9da8-64588d206e38”}
[JSONWP Proxy] Got response with status 200: {“sessionId”:“19eb6a10-fb21-4fd4-a9e5-096313bf43ce”,“status”:0,“value”:true}
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/element/ec6d74a7-202b-4b67-9da8-64588d206e38/click 200 58 ms - 76
[HTTP] --> POST /wd/hub/session/e1f257ef-4a7d-426b-82d3-b9df5eb71eb8/elements {“using”:“xpath”,“value”:"//android.view.View[@index=‘2’]"}
[MJSONWP] Calling AppiumDriver.findElements() with args: [“xpath”,"//android.view.View[@index=‘2’]",“e1f257ef-4a7d-426b-82d3-b9df5eb71eb8”]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 30000 ms for condition

@SnehaBadlani logs stops on place looking for element with xpath //android.view.View[@index=‘2’].

Is this your problem element you waiting for click?

@Aleksei- No, the problem element is this -> //android.widget.Button[@text='Get Started ']"

Since it is getting true for the click event of this element, it is moving ahead in the code to find

-[“xpath”,"//android.view.View[@index=‘2’]".

Since this element ([“xpath”,"//android.view.View[@index=‘2’]") lies on the next screen and is displayed if ( //android.widget.Button[@text='Get Started ']") is clicked.

So the problem is, although true is returned for the click event.The click action never takes place on the device.

@SnehaBadlani try following:

  1. switch to touch events. Try never use clicks for touches. Click is for mouse.

  2. if it not help enable in developer mode to show touches and visially check where it happens on screen.

Good luck

@Aleksei I tried both of your suggestions.

I saw that findElement is getting wrong coordinates of the element, hence the tap is happening on a wrong element that is not clickable.

I checked the page source too, and saw that bounds of the element are incorrect.

Do you think there is a problem with the apk itself?

@SnehaBadlani it pure up to you how to continue. Either correct tap yourself (touch actions allow to add offset) or ask dev for help to fix layout.

At least you know the problem now.