Tap() Vs Click() in Android

Hi,

I am new to Appium and trying to select an object in the screen using the Tap() method in a native android app, the script passes successfully but the the object is not selected in the screen. when I use the click() method it works as expected. Here is my code snippet and the server log.

import static org.junit.Assert.*;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.SwipeElementDirection;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;

public class Exercise {

@Test
public void test() throws MalformedURLException {
	DesiredCapabilities cap= new DesiredCapabilities();
	cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
	cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");
	cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.app.package");
	cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.app.MainActivity");
	AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);
	driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
	MobileElement songselection = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Artists\")");
	songselection.swipe(SwipeElementDirection.UP, 500);
	MobileElement songs = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Song\")");
	songs.swipe(SwipeElementDirection.UP, 500);
	TouchAction touch =new TouchAction(driver);
	touch.tap(driver.findElementByAndroidUIAutomator("UiSelector().text(\"Song1\")"));
}

}

Server log:

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:true}

[debug] [AndroidBootstrap] Received command result from bootstrap

[MJSONWP] Responding to client with driver.performTouch() result: true
[HTTP] <-- POST /wd/hub/session/ecfda199-0f76-429e-8b47-b80243b8248d/touch/perform 200 232 ms - 76
[HTTP] --> POST /wd/hub/session/ecfda199-0f76-429e-8b47-b80243b8248d/element {“using”:"-android uiautomator",“value”:“UiSelector().text(“Anegan (Original Motion Picture Soundtrack)”)”}
[MJSONWP] Calling AppiumDriver.findElement() with args: ["-android uiautomator",“Ui…
[debug] [BaseDriver] Waiting up to 20000 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:”-android uiautomator",“selector”:“UiSelector().text(“Song1”)”,“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:"-android uiautomator",“selector”:“UiSelector().text(“Song1”)”,“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘UiSelector().text(“Song1”)’ using ‘ANDROID_UIAUTOMATOR’ with the contextId: ‘’ multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: UiSelector().text(“Song1”)
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: “Song1”
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=Song1]

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:{“ELEMENT”:“3”}}

[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.findElement() result: {“ELEMENT”:“3”}

[HTTP] <-- POST /wd/hub/session/ecfda199-0f76-429e-8b47-b80243b8248d/element 200 555 ms - 87

But when I try to select the same object using click() functionality it works as expected, the object in the screen is selected as expected.

import static org.junit.Assert.*;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.SwipeElementDirection;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;

public class Exercise {

@Test
public void test() throws MalformedURLException {
	DesiredCapabilities cap= new DesiredCapabilities();
	cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
	cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");
	cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.app.package");
	cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.app.MainActivity");		     		AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);
	driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
	MobileElement songselection = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Artists\")");
	songselection.swipe(SwipeElementDirection.UP, 500);
	MobileElement songs = (MobileElement) driver.findElementByAndroidUIAutomator("new UiSelector().text(\"Song\")");
	songs.swipe(SwipeElementDirection.UP, 500);
	TouchAction touch =new TouchAction(driver);
	driver.findElementByAndroidUIAutomator("UiSelector().text(\"Song1\")").click();

}
}

Server log:
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.performTouch() result: true

[HTTP] <-- POST /wd/hub/session/a0f369fb-cd09-4bc2-8b6d-6d221acffd5a/touch/perform 200 242 ms - 76
[HTTP] --> POST /wd/hub/session/a0f369fb-cd09-4bc2-8b6d-6d221acffd5a/element {“using”:"-android uiautomator",“value”:“UiSelector().text(“Song1”)”}
[MJSONWP] Calling AppiumDriver.findElement() with args: ["-android uiautomator",“Ui…
[debug] [BaseDriver] Waiting up to 20000 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:”-android uiautomator",“selector”:“UiSelector().text(“Song1”)”,“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:"-android uiautomator",“selector”:“UiSelector().text(“Song1”)”,“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘UiSelector().text(“Song1”)’ using ‘ANDROID_UIAUTOMATOR’ with the contextId: ‘’ multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: UiSelector().text(“Song1”)
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: “Song1”
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=Song1]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:{“ELEMENT”:“3”}}
[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.findElement() result: {“ELEMENT”:“3”}
[HTTP] <-- POST /wd/hub/session/a0f369fb-cd09-4bc2-8b6d-6d221acffd5a/element 200 25 ms - 87
[HTTP] --> POST /wd/hub/session/a0f369fb-cd09-4bc2-8b6d-6d221acffd5a/element/3/click {“id”:“3”}
[MJSONWP] Calling AppiumDriver.click() with args: [“3”,"a0f369fb-cd09-4bc2-8b…

[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“element:click”,“params”:{“elementId”:“3”}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“element:click”,“params”:{“elementId”:“3”}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:true}

[debug] [AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.click() result: true

Could you please share the differences between the Tap() and Click() function.

Thanks.