Tapping on any WebElement on screen is same as clicking on the object, (just, tap word is a mobile term), but tap method provides some more features.
To tap on any position on screen or center of a webElement, java-client have a class TouchAction which provides 3
methods
Refer – java-client docs
Syntax –
TouchAction tc = new TouchAction(driver);
tc.tap(element).perform();
Let’s see the code implementation
Using system settings app of android handset.
Settings app : Display -> Brightness level -> tap on seek bar to set the level
public class Tap { static DesiredCapabilities cap; static AndroidDriver driver; @BeforeTest public static void setup() throws MalformedURLException { cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.PLATFORM, "Android"); cap.setCapability(CapabilityType.VERSION, "5.1.0"); cap.setCapability("deviceName", "mygeny510"); cap.setCapability("appPackage", "com.android.settings"); cap.setCapability("appActivity", ".Settings"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap); } @Test public static void Tapping() throws InterruptedException { WebElement Display = driver.findElement(By.name("Display")); //Either tap or click on element, tap(webelement el); //Display.click(); TouchAction tc = new TouchAction(driver); tc.tap(Display).perform(); WebElement brightLevel = driver.findElement(By.name("Brightness level")); brightLevel.click(); WebElement SeekBar = driver.findElement(By.className("android.widget.SeekBar")); TouchAction tc1 = new TouchAction(driver); tc1.tap(SeekBar, 10, 0).perform(); } @AfterTest public static void TearDown() { driver.quit(); } }
Short link – bit.ly/qav-apmtap
How do I double tap on a particular element on the screen in appium?