Hi,
I got into similar issue. I am using following versions of dependencies:
- Appium server 2.4.1
- Appium UiAutomator2 driver 2.45.1
- Appium Java Client 9.2.3
I had a cutom long press code implemented via W3C Gesture that moves to center of element, press down on element, hold for 5 seconds, and then move up the pointer. Something like this:
PointerInput finger1 = new PointerInput(PointerInput.Kind.TOUCH, "finger1");
Sequence sequence = new Sequence(finger1, 1)
.addAction(finger1.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), point.x, point.y))
.addAction(finger1.createPointerDown(PointerInput.MouseButton.LEFT.asArg()))
.addAction(new Pause(finger1, touchDownDuration))
.addAction(finger1.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Collections.singletonList(sequence));
It was all working fine both locally on my real device Samsung Galaxy S20 Android 13, and remotely on BrowserStack real device Samsung Galaxy S24 Ultra Android 14.
I started facing this issue on remote execution which was throwing following error:
org.openqa.selenium.InvalidElementStateException: Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.
Build info: version: '4.19.0', revision: '5f9cec8963'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '14.5', java.version: '17.0.2'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [1286270c040ee4f6560f951c4d1a2393e79a13d9, actions {actions=[org.openqa.selenium.interactions.Sequence@626b639e]}]
at [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at [email protected]/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at [email protected]/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at [email protected]/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at [email protected]/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at app//org.openqa.selenium.remote.ErrorCodec.decode(ErrorCodec.java:167)
at app//org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:138)
at app//org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:50)
at app//org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:190)
at app//io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:237)
at app//org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
at app//org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:604)
at app//com.dcs.appium.core.utils.GestureUtils.tap(GestureUtils.java:112)
I have a test case where I needed to long press multiple elements on screen to retrieve the copied text from clipboard. It works fine on long pressing the first element, however when it attempts to execute long press on second element then I get above error.
In my opinion, this is not related to element since I tried interchanging or trying with different elements and it always worked fine for first long press action, and on subsequent long presses I got this error.
My hypothesis for this error is that when an element is long pressed, then Android displays a system toaster message indicating text is copied to clipboard which stays on screen for sometime, and if we attempt to long press another element while this toaster is being displayed, then we get this error. However I doubt this is the case, because it still works fine locally and toaster is not obstructing the view of element to be clicked.
I inspected the device logs from logcat but i could not find anything related. The error message also does not point to what exactly to look for in device logs.
Nevertheless, I tried the long press from appium-uiautomator2-driver/docs/android-mobile-gestures.md at master · appium/appium-uiautomator2-driver · GitHub which solved the issue.
I am still curious to understand what could possibly have gone wrong all of a sudden as the code was running just fine with same libraries and device under test previously. The only change that I can think of is extra capability that I added androidOptions.setDisableSuppressAccessibilityService(false);
because it is false by default however BrowserStack sets it to true so i am passing it explicitly to make it false.