On longPress in Android device(Google Pixel) - InvalidElementStateException: Unable to perform W3C actions. Check logcat output

@Aleksei I’ m getting this error: org.openqa.selenium.InvalidStateException: Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.

I’m using appium 2.0 and performing a longPress action on an element where I’m getting this issue intermittently. The device being used in Google Pixel on Android version 12.

Any idea of what could be going wrong??

No idea without your code including 1-2 actions before.
0 ios or android ?
1 how you find element ?
2 how you make long tap ?

@Aleksei

0: Its an Android device - Google Pixel and Android version 12

1: I use @AndroidFindBy annotation implementing the pagefactory model to find the element:-
@AndroidFindBy(uiAutomator = “new UiSelector().descriptionContains("App Info")”)
WebElement appInfoBtn;

2: Use the below longPress() method to implement the same with below code snippet:
public void longPress(AppiumDriver driver, WebElement ele) {
Point location = ele.getLocation();
Dimension size = ele.getSize();
Point centreofElem = getCenterofElem(location, size);

    PointerInput pressFinger = new PointerInput(PointerInput.Kind.TOUCH,"finger");
    Sequence seq = new Sequence(pressFinger, 1)
            .addAction(pressFinger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), centreofElem))
            .addAction(pressFinger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()))
            .addAction(new Pause(pressFinger, Duration.ofSeconds(1)))
            .addAction(pressFinger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));

             driver.perform(Collections.singletonList(seq));
}

and you get exception on below line?

@Aleksei
Yes, exactly it fails on this very line: driver.perform(Collections.singletonList(seq));

Also, this is the below code to getCenterofElement:

private Point getCenterofElem(Point locn, Dimension size) {
int leftX = locn.getX();
int midX = leftX + (size.getWidth()/2);

int upperY = locn.getY();
int midY = upperY + (size.getHeight()/2);

return new Point(midX, midY);
}

Did you try add simple sleep for e.g. 5 sec before LongTap on element BUT after needed screen loaded?
Just to check…

@Aleksei So what are u suggesting in this case?? Should I add some sleep before performing the longPress?? In case so should I add it before calling the longPress() method or before this line- driver.perform(Collections.singletonList(seq))

Post this longPress method, I wait for the next screen 1st element visibility (which is basically a textField) by using a fluentwait and Expectedconditions.visibilityofelemntLocated() so I guess that should take care of screenLoad check.

You did not answer: does simple sleep helps you?

I still hardly believe that InvalidStateException happens inside driver.perform(Collections.singletonList(seq));. As far as NO element here and long tap happens by coordinates.

I haven’t added any sleep as of now and that’s what I asked u previously…Do I need to add sleep and if so then at which step??

Should I add it before longPress?? And if so then at which point?? after getting the co-ordinates or before getting it??

see question above.

Also you can try other solution → appium-uiautomator2-driver/docs/android-mobile-gestures.md at master · appium/appium-uiautomator2-driver · GitHub

@Aleksei
I did try with sleep and that isn’t working out…But with the other suggestion of yours related to mobile gesture seems to work fine for now…Let me try with that for couple of runs on Jenkins…I hope so that should be stable and work smoothly !!

Thanks much for your suggestion !! Will update on this thread if the mobile gesture is working seamlessly for this issue !!

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.

Tried disable animation capability with android? It may help to reduce state element issue

I tried these suggestions but they still did not resolve issue with W3C Long Tap

  • Disable animations via UiAutomator2 appium:disableWindowAnimation
  • Disable BrowserStack device animations
  • Adding a wait of 10 seconds before subsequent long tap

Here are the Appium Server Logs:

2024-07-30 10:09:32:295 - [HTTP] --> POST /wd/hub/session/c0d2eab5-637b-44b1-90bd-f6aef3e21846/actions
2024-07-30 10:09:32:295 - [HTTP] {"actions":[{"id":"finger1","type":"pointer","parameters":{"pointerType":"touch"},"actions":[{"duration":0,"type":"pause"},{"duration":0,"x":521,"y":1791,"type":"pointerMove","origin":"viewport"},{"button":0,"type":"pointerDown"},{"duration":5000,"type":"pause"},{"button":0,"type":"pointerUp"}]}]}
2024-07-30 10:09:32:295 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] Calling AppiumDriver.performActions() with args: [[{"id":"finger1","type":"pointer","parameters":{"pointerType":"touch"},"actions":[{"duration":0,"type":"pause"},{"duration":0,"x":521,"y":1791,"type":"pointerMove","origin":"viewport"},{"button":0,"type":"pointerDown"},{"duration":5000,"type":"pause"},{"button":0,"type":"pointerUp"}]}],"c0d2eab5-637b-44b1-90bd-f6aef3e21846"]
2024-07-30 10:09:32:296 - [AppiumDriver@15dc] Clearing new command timeout pre-emptively since plugin(s) will handle this command
2024-07-30 10:09:32:296 - [AppiumDriver@15dc] Plugins which can handle cmd 'performActions': images
2024-07-30 10:09:32:296 - [AppiumDriver@15dc] Plugin images is now handling cmd 'performActions'
2024-07-30 10:09:32:296 - [AppiumDriver@15dc] Executing default handling behavior for command 'performActions'
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] Received the following W3C actions: [
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]   {
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     "id": "finger1",
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     "type": "pointer",
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     "parameters": {
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       "pointerType": "touch"
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     },
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     "actions": [
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "duration": 0,
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pause"
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       },
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:296 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "duration": 0,
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "x": 521,
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "y": 1791,
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pointerMove",
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "origin": "viewport"
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       },
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "button": 0,
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pointerDown"
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       },
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "duration": 5000,
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pause"
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       },
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "button": 0,
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pointerUp"
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       }
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     ]
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]   }
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] ]
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] Preprocessed actions: [
2024-07-30 10:09:32:297 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]   {
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     "id": "finger1",
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     "type": "pointer",
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     "parameters": {
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       "pointerType": "touch"
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     },
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     "actions": [
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "duration": 0,
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pause"
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       },
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "duration": 0,
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "x": 521,
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "y": 1791,
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pointerMove",
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "origin": "viewport"
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       },
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "button": 0,
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pointerDown"
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       },
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "duration": 5000,
2024-07-30 10:09:32:298 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pause"
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       },
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       {
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "button": 0,
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]         "type": "pointerUp"
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]       }
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]     ]
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)]   }
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] ]
2024-07-30 10:09:32:299 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] Matched '/actions' to command name 'performActions'
2024-07-30 10:09:32:300 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] Proxying [POST /actions] to [POST http://127.0.0.1:8203/session/3af37a41-ab24-4bc9-85b6-05a5a4649755/actions] with body: {"actions":[{"id":"finger1","type":"pointer","parameters":{"pointerType":"touch"},"actions":[{"duration":0,"type":"pause"},{"duration":0,"x":521,"y":1791,"type":"pointerMove","origin":"viewport"},{"button":0,"type":"pointerDown"},{"duration":5000,"type":"pause"},{"button":0,"type":"pointerUp"}]}]}
2024-07-30 10:09:37:353 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] Got response with status 400: {"sessionId":"3af37a41-ab24-4bc9-85b6-05a5a4649755","value":{"error":"invalid element state","message":"Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.","stacktrace":"io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.\n\tat io.appium.uiautomator2.handler.W3CActions.safeHandle(W3CActions.java:82)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.ch...
2024-07-30 10:09:37:353 - [W3C] Matched W3C error code 'invalid element state' to InvalidElementStateError
2024-07-30 10:09:37:360 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] Encountered internal error running command: io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.
2024-07-30 10:09:37:360 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.appium.uiautomator2.handler.W3CActions.safeHandle(W3CActions.java:82)
2024-07-30 10:09:37:360 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)
2024-07-30 10:09:37:360 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)
2024-07-30 10:09:37:360 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)
2024-07-30 10:09:37:360 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)
2024-07-30 10:09:37:360 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
2024-07-30 10:09:37:360 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
2024-07-30 10:09:37:361 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
2024-07-30 10:09:37:362 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
2024-07-30 10:09:37:362 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
2024-07-30 10:09:37:362 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
2024-07-30 10:09:37:362 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
2024-07-30 10:09:37:362 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
2024-07-30 10:09:37:362 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 	at java.lang.Thread.run(Thread.java:1012)
2024-07-30 10:09:37:362 - [AndroidUiautomator2Driver@1186 (c0d2eab5)] 
2024-07-30 10:09:37:362 - [HTTP] <-- POST /wd/hub/session/c0d2eab5-637b-44b1-90bd-f6aef3e21846/actions 400 5067 ms - 3891
2024-07-30 10:09:37:362 - [HTTP] 

My obvious guess is something wrong with BrowserStack, as same code works fine locally as well as on emulator.

What I do not understand is how the long tap gesture from UiAutomator2 works differently to not get the same error?

Below are the Appium Server logs from longClick gesture performed via UiAutomator2:

2024-07-30 10:06:04:936 - [HTTP] --> POST /wd/hub/session/97514d43-9cbd-448d-9b75-026b08fe8a9c/execute/sync
2024-07-30 10:06:04:936 - [HTTP] {"script":"mobile: longClickGesture","args":[{"elementId":"00000000-0000-085b-0000-006d00000115","duration":5000,"x":0,"y":0}]}
2024-07-30 10:06:04:936 - [AndroidUiautomator2Driver@1bb6 (97514d43)] Calling AppiumDriver.execute() with args: ["mobile: longClickGesture",[{"elementId":"00000000-0000-085b-0000-006d00000115","duration":5000,"x":0,"y":0}],"97514d43-9cbd-448d-9b75-026b08fe8a9c"]
2024-07-30 10:06:04:936 - [AppiumDriver@6237] Clearing new command timeout pre-emptively since plugin(s) will handle this command
2024-07-30 10:06:04:936 - [AppiumDriver@6237] Plugins which can handle cmd 'execute': images
2024-07-30 10:06:04:936 - [AppiumDriver@6237] Plugin images is now handling cmd 'execute'
2024-07-30 10:06:04:937 - [AppiumDriver@6237] Executing default handling behavior for command 'execute'
2024-07-30 10:06:04:937 - [AndroidUiautomator2Driver@1bb6 (97514d43)] Executing method 'mobile: longClickGesture'
2024-07-30 10:06:04:943 - [AndroidUiautomator2Driver@1bb6 (97514d43)] Proxying [POST /appium/gestures/long_click] to [POST http://127.0.0.1:8204/session/88b4febd-5ee0-417d-b1f7-e25a2a53b14f/appium/gestures/long_click] with body: {"origin":{"ELEMENT":"00000000-0000-085b-0000-006d00000115","element-6066-11e4-a52e-4f735466cecf":"00000000-0000-085b-0000-006d00000115"},"offset":{"x":0,"y":0},"duration":5000}
2024-07-30 10:06:10:815 - [AndroidUiautomator2Driver@1bb6 (97514d43)] Got response with status 200: {"sessionId":"88b4febd-5ee0-417d-b1f7-e25a2a53b14f","value":null}
2024-07-30 10:06:10:816 - [AndroidUiautomator2Driver@1bb6 (97514d43)] Responding to client with driver.execute() result: null
2024-07-30 10:06:10:816 - [HTTP] <-- POST /wd/hub/session/97514d43-9cbd-448d-9b75-026b08fe8a9c/execute/sync 200 5880 ms - 14