Appium Python tests break where TouchAction press and long_press were used
Your error
ModuleNotFoundError: No module named 'appium.webdriver.common.touch_action'1 more line it can showFix it fast
Most common cause, 1 of 3The installed client no longer ships TouchAction
Delete the old imports and replace each press, wait and release chain with Selenium's W3C action builder.
from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput
def long_press_at(driver, x, y, seconds=2):
actions = ActionChains(driver)
actions.w3c_actions = ActionBuilder(driver, mouse=PointerInput(interaction.POINTER_TOUCH, "touch"))
actions.w3c_actions.pointer_action.move_to_location(x, y)
actions.w3c_actions.pointer_action.pointer_down()
actions.w3c_actions.pointer_action.pause(seconds)
actions.w3c_actions.pointer_action.release()
actions.perform()Short answer
TouchAction and MultiAction were removed in Appium-Python-Client 4.0, so the import of appium.webdriver.common.touch_action fails on 4.x to 6.1.8. Pinning 3.x is no fix either, because Appium 3 and 4 servers dropped the /touch/perform route it calls. Rewrite press() and long_press() as W3C actions with a touch pointer, or call mobile: longClickGesture or touchAndHold.
Which cause do you have?
Print the client version and the server version side by side. A client of 4.0 or newer points to cause 1. A 3.x client talking to an Appium 3 or 4 server points to cause 2. If both are current and your new gesture runs without effect, read cause 3.
pip show Appium-Python-Client | grep -i '^version'
appium --versionThen find the line you see in this list and open its fix:
- 1The installed client no longer ships TouchAction
pip show reports 4.0 or later, and the test stops at the import line before any session starts - 2An old client was pinned, but the server dropped the touch routes
pip show reports 3.x, the DeprecationWarning prints, and the gesture call fails only after the session has started - 3The W3C rewrite runs, but the app sees no long press
No exception is raised, the action finishes, yet the context menu or drag handle never shows
What does the error look like?
ModuleNotFoundError: No module named 'appium.webdriver.common.touch_action'DeprecationWarning: [Deprecated] 'TouchAction' action is deprecated. Please use W3C actions instead.
Cause 1 of 3
The installed client no longer ships TouchAction
You seepip show reports 4.0 or later, and the test stops at the import line before any session starts
Check
The ModuleNotFoundError for appium.webdriver.common.touch_action appears because version 4.0.0 of the Python client, released on 11 March 2024, deleted TouchAction and MultiAction as calls outside the W3C WebDriver standard. Every release since then, up to 6.1.8, lacks both classes.
grep -rn "TouchAction\|MultiAction" --include=*.py .Fix
Delete the old imports and replace each press, wait and release chain with Selenium's W3C action builder. Switch the builder to a touch pointer, since the client README says UiAutomator2 treats touch input and mouse input differently. A pause between pointer_down and release turns a tap into a long press.
from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput
def long_press_at(driver, x, y, seconds=2):
actions = ActionChains(driver)
actions.w3c_actions = ActionBuilder(driver, mouse=PointerInput(interaction.POINTER_TOUCH, "touch"))
actions.w3c_actions.pointer_action.move_to_location(x, y)
actions.w3c_actions.pointer_action.pointer_down()
actions.w3c_actions.pointer_action.pause(seconds)
actions.w3c_actions.pointer_action.release()
actions.perform()Verify
The grep finds no TouchAction or MultiAction left, the suite gets past the imports, and the long press opens the menu or selection it used to open.
grep -rn "touch_action\|multi_action" --include=*.py . || echo cleanConfirmed by raw.githubusercontent.com
Cause 2 of 3
An old client was pinned, but the server dropped the touch routes
You seepip show reports 3.x, the DeprecationWarning prints, and the gesture call fails only after the session has started
Check
Keeping Appium-Python-Client below 4 brings the import back, yet TouchAction still talks to the old JSONWP endpoint POST /session/:sessionId/touch/perform. The Appium 3 migration guide lists that route, MultiAction's /touch/multi/perform and /touch/longclick among the endpoints removed from the server, with W3C actions as the replacement.
python -W default -c "from appium.webdriver.common.touch_action import TouchAction; TouchAction()"Fix
Stop pinning the 3.x client. Upgrade it to a current release and port the gestures as in cause 1, so both sides speak the W3C protocol.
pip install --upgrade "Appium-Python-Client>=6.1"
pip show Appium-Python-Client | grep -i '^version'Verify
The version line shows 6.1 or later, the DeprecationWarning no longer prints, and the rewritten gestures succeed against the Appium 3 or 4 server.
python -m pytest -k long_press -W error::DeprecationWarningConfirmed by appium.io
Cause 3 of 3
The W3C rewrite runs, but the app sees no long press
You seeNo exception is raised, the action finishes, yet the context menu or drag handle never shows
Check
A replacement that uses ActionChains with its default mouse pointer, or a pause that is too short, can finish without the app ever reacting. The client README warns that gesture behaviour varies across drivers and pointer types, so a driver-native gesture is the safer choice for a long press.
grep -rn "ActionChains(\|click_and_hold" --include=*.py .Fix
Call the driver's own long press command. On Android, UiAutomator2 takes an elementId (or x and y) and a duration in milliseconds, 500 by default. On iOS, XCUITest's touchAndHold needs a duration in seconds as a float.
# Android (UiAutomator2): duration in milliseconds
driver.execute_script("mobile: longClickGesture", {"elementId": el.id, "duration": 2000})
# iOS (XCUITest): duration in seconds
driver.execute_script("mobile: touchAndHold", {"elementId": el.id, "duration": 2.0})Verify
The element reacts the way a finger hold does on a real device: a context menu, a selection or an edit mode appears.
python -m pytest -k long_press -vConfirmed by appium.github.io
How do I stop it coming back?
- Pin Appium-Python-Client with a lower bound such as >=6.1 in requirements, so an old lock file cannot pull TouchAction-era code back.
- Keep every gesture in one helper module, so a driver change means editing one file instead of every test.
- Run the suite with -W error::DeprecationWarning in CI, which turns the next client deprecation into a failing build before the removal lands.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.