How to use touch actions in Appium?

On This Page Understanding Touch Actions in AppiumJune 06, 2026 · 14 min read · Tool Comparison

How to use touch activeness in Appium?

Mobile apps rely heavily on gestures like taps, swipe, and scroll. Appium supports these through touch actions, enabling naturalistic mobile test automation. Touch actions in Appium objects contain a concatenation of case. The TouchAction object is first initialized in the WebDriver and then the steps are chained together to perform the action.

Overview

Understanding Touch Actions

  • Mobile testing requires simulating existent user motion.
  • It is essential for testing apps with rich UI/UX.

Canonical Touch Actions

  • Tap & # 8211; single pressure.
  • Long pressure & # 8211; Press and hold for a few seconds.
  • Swipe & # 8211; Press and drag to move across the blind.
  • Multi-touch & # 8211; utilize for gestures like Zoom-in, Zoom-out

Installing and Setting Up Appium

  • Set Java surroundings variable, Install NodeJS, NPM and Appium.
  • Configure Android Virtual Devices and start a new Android virtual emulator.
  • Connect the Appium server with your model and execute tests.

This article outlines different touch actions and how to implement them with Appium.

Understanding Touch Actions in Appium

There are some appium touch actions in Appium such as:

  1. Swipe
  2. Tap
  3. Long Press
  4. Multi-touch

1. Swipe 

Press by using x, y coordinates, and duration (in seconds) Horizontal swipe by using the start and end percentage of the phone blind and a point for the height—vertical swipe by using the start and end percentage of the screen and an anchor for the width. Swipe one element to another factor. The swipe has a start and endpoints. The start point of swipe is the most crucial.

The following component may prevent swipe start: covering interface/menu e.g. cope or footer & # 8211; an element that is waiting for tap and do not pass trace to scroll survey

This is best to start swipe actions at the center point of the screen to make them more stable.

2. Tap 

Tap and click sometimes suffer from the elements not being valid anymore and returning “not able to tap element”.

That said, we usually use taps on buttons. Whenever we get any job with tapping on visible elements (but appium states they aren ’ t visible, etc.) we useTouchAction.new.presson Element. So no take-care cost and it always exhort on the spot even when tap/click perform not act.

3. Long Press

The act of pressing one & # 8217; s finger down on an element or former portion of the screen for a few seconds, as to activate a job or access additional selection. When we need to rotate any app icon on the screen then we need long press that app icon and then scroll it on a earpiece screen.

4. Multi-touch

Multi-touch allows you to touch the screen with multiple fingers and perform action. Multi-touch is usually used for gesture like Zoom-in, Zoom-out, Drag and Drop. In Appium, multi-touch actions can be performed using theMultiTouchActionclass. This class allows you to create complex touch actions involving multiple fingers on the touch screen.

Read More:

Differences between Android and iOS touch actions in Appium

iOS and Android both use touch actions that have a common operation & # 8211;swiping, tapping, pinch,and zoom. Both OS boot to a home screen, which is alike to a computer desktop. While an iOS home blind only has rows of app icons, Android allows the use of thingumajig, which display auto-updating details such as weather and email. The iOS user UI features an mind where user can pin their most frequently used coating.

A status bar lead across at the upper side on both iOS and Android, offering information such as the clip, WiFi or cell signal, and battery life; on Android, the status bar also seeable the number of new coming email, messages, and reminders.

Installing and Setting Up Appium

1. Install JDK

Specify the route to the JDK version in theJAVA_HOMEenvironment variable. To do this, open the Control Panel, search forenvironment variables, in the dialogue, click Environment Variables, and then set the variable and put the value:

2. Install NodeJS and NPM

3. Install Appium employ the below bidding

npm install -g appium

After the installation, start Appium to confirm it is working amercement.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

4. Install Android Studio

Note: When installing, take precaution to select theAndroid Virtual Deviceportion as seen in the image below

5. Configure Android Virtual Devices

  • Start Android Studio.
  • In the First duologue, selectConfigure & gt; SDK Manager.
  • On the SDK Window, select the SDKs that are take for testing. Select at least one SDK.
    • Switch to theSDK Toolstab and confirm the following puppet are selected there:
      • Android SDK Build-tools
      • Android SDK Platform-Tools
      • Intel x86 Emulator Accelerator (HAXM installer)
    • Copy the itinerary of theAndroid SDK Locationbox at the up side of the SDK Manager dialogue. We will need this value later:
    • Close the SDK Manager.
  • Now, in the First dialogue, selectConfigure & gt; AVD Manager. This will open the AVD Manager dialogue where you can create and commence new Android practical devices (emulators).
    If the dialog box doesn ’ t list the twist you need, tickCreate Virtual Deviceand create the required gimmick emulator.
  • To create and run examination, you need to give the way to Android SDK file in theANDROID_HOMEenvironment variable: open the Control Panel, hunt for “environment variables”, in the subsequent dialog, click Environment Variables, and then set the varying value. If the variable doesn ’ t feature in tilt, add it to the “System variables” list:

After Successfully set-up and configuring for appium and having wandering devices managed, you can connect to it from yourTestCompleteestimator to make and run tests.

Creating Basic Test Script For Touch Actions

Here, we will excuse how you can use different touch activeness in Appium expend Python by creating a introductory test suit for each of them.

1. Using Tap Touch Action in Appium: Example

The below code helps you can perform the Tap Touch activeness in Appium

from appium import webdriver from appium.webdriver.common.touch_action importation TouchAction from appium.webdriver.common.appiumby meaning AppiumBy significance time # Step 1: Create `` Desired Capabilities '' desired_caps = {} desired_caps ['platformName '] = 'Android' desired_caps ['platformVersion '] = '10' desired_caps ['deviceName '] = 'Pixel3XL' desired_caps ['appPackage '] = 'com.browserstack.demo.app' desired_caps ['appActivity '] = 'host.exp.exponent.MainActivity' desired_caps ['udid '] = 'emulator-5554' # Step 2: Create `` Driver target '' driver = webdriver.Remote (`` http: //127.0.0.1:4723/wd/hub '', desired_caps) time.sleep (8) ele = driver.find_element (AppiumBy.XPATH, '//android.widget.TextView [@ content-desc= '' filter-btn ''] ') # Step 3: Create the object the TouchAction category actions = TouchAction (driver) # Step 4: Call the tap () method and pass the arguments. actions.tap (ele) .perform () time.sleep (5) driver.quit ()

2. Using Long Press Touch Action in Appium: Example

The below code helps you can perform Long Press touch activeness in Appium

from appium signification webdriver from appium.webdriver.common.touch_action import TouchAction from appium.webdriver.common.appiumby significance AppiumBy importee time # Step 1: Create `` Desired Capabilities '' desired_caps = {} desired_caps ['platformName '] = 'Android' desired_caps ['platformVersion '] = '10' desired_caps ['deviceName '] = 'Pixel3XL' desired_caps ['appPackage '] = 'com.browserstack.demo.app' desired_caps ['appActivity '] = 'host.exp.exponent.MainActivity' desired_caps ['udid '] = 'emulator-5554' # Step 2: Create `` Driver object '' driver = webdriver.Remote (`` http: //127.0.0.1:4723/wd/hub '', desired_caps) time.sleep (8) ele = driver.find_element (AppiumBy.XPATH, '//android.widget.TextView [@ content-desc= '' filter-btn ''] ') # Step 3: Create the object the TouchAction grade actions = TouchAction (driver) actions.long_press (ele) actions.perform () time.sleep (5) driver.quit ()

3. Swipe without Touch Action

Code :

from appium import webdriver import time # Step 1: Create `` Desired Capabilities '' desired_caps = {} desired_caps ['platformName '] = 'Android' desired_caps ['platformVersion '] = '10' desired_caps ['deviceName '] = 'Pixel3XL' desired_caps ['appPackage '] = 'com.browserstack.demo.app' desired_caps ['appActivity '] = 'host.exp.exponent.MainActivity' desired_caps ['udid '] = 'emulator-5554' # Step 2: Create `` Driver object '' driver = webdriver.Remote (`` http: //127.0.0.1:4723/wd/hub '', desired_caps) time.sleep (8) # Step 1: Find the device width and height deviceSize = driver.get_window_size () screenWidth = deviceSize ['width '] screenHeight = deviceSize ['height '] # Step 2: # Step 6: Find the x, y co-ordinate to swipe # # * * * * * * * * * * * down to up * * * * * * * * * * * * * # startx = screenWidth/2 endx = screenWidth/2 starty = screenHeight * 8/9 endy = screenHeight/9 driver.swipe (start_x=startx, start_y=starty, end_x=endx, end_y=endy, duration=100) time.sleep (5) driver.quit ()

4. Swipe with touch activity in Appium

Here ’ s the code to swipe employ touch action in Appium

from appium importation webdriver from appium.webdriver.common.touch_action significance TouchAction from appium.webdriver.common.appiumby import AppiumBy significance time # Step 1: Create `` Desired Capabilities '' desired_caps = {} desired_caps ['platformName '] = 'Android' desired_caps ['platformVersion '] = '10' desired_caps ['deviceName '] = 'Pixel3XL' desired_caps ['appPackage '] = 'com.browserstack.demo.app' desired_caps ['appActivity '] = 'host.exp.exponent.MainActivity' desired_caps ['udid '] = 'emulator-5554' # Step 2: Create `` Driver object '' driver = webdriver.Remote (`` http: //127.0.0.1:4723/wd/hub '', desired_caps) time.sleep (8) ele = driver.find_element (AppiumBy.XPATH, '//android.widget.TextView [@ content-desc= '' filter-btn ''] ') # Step 3: Find the device width and height deviceSize = driver.get_window_size () print (`` Device Width and Height: ``, deviceSize) screenWidth = deviceSize ['width '] screenHeight = deviceSize ['height '] # Step 4: Find the x, y co-ordinate to swipe # * * * * * * * * * * * Left to Right * * * * * * * * * * * * * # startx = screenWidth * 8/9 endx = screenWidth/9 starty = screenHeight/2 endy = screenHeight/2 # * * * * * * * * * * * Right to Left * * * * * * * * * * * * * # startx2 = screenWidth/9 endx2 = screenWidth * 8/9 starty2 = screenHeight/2 endy2 = screenHeight/2 activeness = TouchAction (driver) # Step 5: perform the action swiping from leave to Right actions.long_press (None, startx, starty) .move_to (None, endx, endy) .release () .perform () # Step 6: do the action swiping from Right to Left actions.long_press (None, startx2, starty2) .move_to (None, endx2, endy2) .release () .perform () time.sleep (2) driver.quit ()

Like what you are read?

You can start discussing with our discord community

Advanced Touch Actions

Using advanced touch action like multi-touch actions such as:

  1. Pinch & # 8211; Zoom in using multi-touch
  2. Pinch Zoom-out using multi-touch
  3. Drag & amp; Drop
  4. Drag & amp; Drop habituate an inbuilt function

Here ’ s the elaborate code for each of these complex ghost activeness.

1. Pinch & # 8211; Zoom in using multi-touch

To make any ikon, web page, etc. more seeable and clear to the viewer, the zoom operation maximises and minimises the window.

Or, to put it another way, when you zoom in, the coordinates (x, y) from one place change as it moves to another spot, causing a shift in co-ordinate that enlarge the window and improves user clearness.

from appium import webdriver from appium.webdriver.common.touch_action import TouchAction from appium.webdriver.common.multi_action importee MultiAction from appium.webdriver.common.appiumby import AppiumBy import time # Step 1: Create `` Desired Capabilities '' desired_caps = {} desired_caps ['platformName '] = 'Android' desired_caps ['platformVersion '] = '10' desired_caps ['deviceName '] = 'Pixel3XL' desired_caps ['appPackage '] = 'com.browserstack.demo.app' desired_caps ['appActivity '] = 'host.exp.exponent.MainActivity' desired_caps ['udid '] = 'emulator-5554' # Step 2: Create `` Driver object '' driver = webdriver.Remote (`` http: //127.0.0.1:4723/wd/hub '', desired_caps) time.sleep (8) ele = driver.find_element (AppiumBy.XPATH, '//android.widget.TextView [@ content-desc= '' filter-btn ''] ') # Step 3: Find the twist width and top xx = driver.get_window_size () ['width '] /2 yy = driver.get_window_size () ['height '] /2 # Step 4: Perform zoom-in action1 = TouchAction (driver) action2 = TouchAction (driver) zoom_action = MultiAction (driver) # Zoom action1.long_press (x=xx, y=yy) .move_to (x=0, y=50) .wait (500) .release () action2.long_press (x=xx, y=yy) .move_to (x=0, y=-50) .wait (500) .release () zoom_action.add (action1, action2) time.sleep (2) driver.quit ()

2. Pinch Zoom-out using multi-touch

A zoom-out operation reduce the size of the window for any image, webpage, etc. so that the user can see it more intelligibly and easily.

Or, to put it another way, when you soar out, the coordinates (x, y) from one point modification and are shifted to another point location, which causes a modification in coordinates. This action enlarge the window and improves user lucidness.

from appium import webdriver from appium.webdriver.common.touch_action import TouchAction from appium.webdriver.common.multi_action significance MultiAction from appium.webdriver.common.appiumby import AppiumBy import time # Step 1: Create `` Desired Capabilities '' desired_caps = {} desired_caps ['platformName '] = 'Android' desired_caps ['platformVersion '] = '10' desired_caps ['deviceName '] = 'Pixel3XL' desired_caps ['appPackage '] = 'com.browserstack.demo.app' desired_caps ['appActivity '] = 'host.exp.exponent.MainActivity' desired_caps ['udid '] = 'emulator-5554' # Step 2: Create `` Driver object '' driver = webdriver.Remote (`` http: //127.0.0.1:4723/wd/hub '', desired_caps) time.sleep (8) ele = driver.find_element (AppiumBy.XPATH, '//android.widget.TextView [@ content-desc= '' filter-btn ''] ') # Step 3: Find the device breadth and height xx = driver.get_window_size () ['width '] /2 yy = driver.get_window_size () ['height '] /2 # Step 4: Perform zoom-out action1 = TouchAction (driver) action2 = TouchAction (driver) zoom_action = MultiAction (driver) # Zoom action1.long_press (x=xx-50, y=yy-50) .move_to (x=0, y=50) .wait (500) .release () action2.long_press (x=xx-50, y=yy-50) .move_to (x=0, y=-50) .wait (500) .release () zoom_action.add (action1, action2) time.sleep (2) driver.quit ()

Complex Actions expend Touch Action and Multi-touch Action

Here, we are do some complex actions using touch action and multi-touch in appium

3. Drag & amp; Drop

Moving an element from one place to a particular or defined place command the simultaneous use of the two actions of drag and drop.

An constituent & # 8217; s location, or more specifically its x and y co-ordinate, change throughout the drag and drop event and it is placed in a new location with new x and y coordinates.

In order to do drag-and-drop actions inside mobile applications, Appium offers a set of instructions. The moveTo method, which is component of the Touch Action Class, helps drop the element to its intended place free-base on x and y coordinates by long-pressing the element to be cart.

Read More:

Code to perform Drag and Drop using Touch Actions in Appium

from appium import webdriver from appium.webdriver.common.touch_action import TouchAction from appium.webdriver.common.multi_action significance MultiAction from appium.webdriver.common.appiumby import AppiumBy import time # Step 1: Create `` Desired Capabilities '' desired_caps = {} desired_caps ['platformName '] = 'Android' desired_caps ['platformVersion '] = '10' desired_caps ['deviceName '] = 'Pixel3XL' desired_caps ['appPackage '] = 'com.browserstack.demo.app' desired_caps ['appActivity '] = 'host.exp.exponent.MainActivity' desired_caps ['udid '] = 'emulator-5554' # Step 2: Create `` Driver object '' driver = webdriver.Remote (`` http: //127.0.0.1:4723/wd/hub '', desired_caps) time.sleep (8) # Step 3: Find ingredient for drag and drop drag_ele = driver.find_element (AppiumBy.XPATH, ' & lt; Xpath & gt; ') drop_ele = driver.find_element (AppiumBy.XPATH, ' & lt; Xpath & gt; ') action = TouchAction (driver) action.press (drag_ele) .move_to (drop_ele, 100, 100) .release () .perform () time.sleep (2) driver.quit ()

4. Drag & amp; Drop using an inherent function

from appium import webdriver from appium.webdriver.common.touch_action signification TouchAction from appium.webdriver.common.multi_action import MultiAction from appium.webdriver.common.appiumby import AppiumBy import time # Step 1: Create `` Desired Capabilities '' desired_caps = {} desired_caps ['platformName '] = 'Android' desired_caps ['platformVersion '] = '10' desired_caps ['deviceName '] = 'Pixel3XL' desired_caps ['appPackage '] = 'com.browserstack.demo.app' desired_caps ['appActivity '] = 'host.exp.exponent.MainActivity' desired_caps ['udid '] = 'emulator-5554' # Step 2: Create `` Driver object '' driver = webdriver.Remote (`` http: //127.0.0.1:4723/wd/hub '', desired_caps) time.sleep (8) # Step 3: Find element for drag and drop drag_ele = driver.find_element (AppiumBy.XPATH, ' & lt; Xpath & gt; ') drop_ele = driver.find_element (AppiumBy.XPATH, ' & lt; Xpath & gt; ') action = TouchAction (driver) action.tap (drag_ele) .perform () driver.drag_and_drop (drag_ele, drop_ele) time.sleep (2) driver.quit ()

Read More:

Best Practices for using Touch Actions in Appium

Listed below are some of the key best pattern that you can follow when using touch actions in Appium:

  • Drag and drop operation can be performed using theTouchAction and MultiTouchAction classes.
  • Press, waitAction and moveTomethods should be called in sequence to perform drag and drop
  • Using the getLocationfunction, we can situate the Point of Source and Destination ingredient.
  • Lastly, drag and drop action may be transmit out using theMultiTouchActionclass & # 8217; s perform function.
  • The same principles apply when dragging and dropping an element. The lone distinction is that there is no finish element. We can use goal point in this situation.
  • In a similar manner, we may carry out this action on iOS.

Common issues / Challenges with Touch Actions in Appium

Here are some of the common topic / challenge that you may encounter with touch activeness in Appium:

  1. Unrestricted X Path Usage:Although undue X Path usage has be observed in the Selenium cosmos as well, it has more absurd repercussions in the Appium world since X Path is a more active proficiency to expose the elements. Xpaths and the type of Xpath we are just expend must be considered while working with touch actions in appium. Attempt to utilise a dynamic Xpath to ignore constituent not visible job.
  2. Neglected usage of Accessibility IDs:To read an item-by-item identifier for a UI component, the accessibility ID locator strategy was developed. The best way to recover an element for touch actions on iOS and Android is by its accessibility ID. Because every constituent have your own unique id which is provided by developers.
  3. Query for every ingredient visibility:Another option to foreshorten the run-time of the Appium test script is to avoid enquire for each element & # 8217; s visibility. As a result, Appium experiences an increased mass of calls and hold time throughout each action of fetching an element. By just asking the element characteristics that matter from the exam code & # 8217; s point of view, the lag can be decreased.

Read More:

Conclusion

So, In this clause, we have touch action, multi-touch activity, and action chain uses with different points of survey and operation in applications for prove any app. Here we have cabbage, scroll, sweep & amp; drop operations, Zoom In, and Zoom out. Succeeding, we can try these operations by using W3C Protocol in appium. also render the environment for performing these operations with different device and versions.

Tags
34,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free