Action API class not working on Android emulator

Hi,

I would like some help with the action API class. We were using the touchAction API previously, however this was deprecated in the more recent versions of Appium. Our test framework is webdriver.io

webdriver.io docs:
touchAction | WebdriverIO

Appium deps:

 "appium": "2.5.1",
 "appium-uiautomator2-driver": "3.0.1",
 "appium-xcuitest-driver": "7.2.0",

Code to scroll on mobile device:

async scrollToFindElement(
    checkElement: WebdriverIO.Element,
    coordinates: Coordinates,
    numberOfRetries = 10,
  ) {
    const destinationY =
      coordinates.originY + coordinates.destinationY > 0
        ? coordinates.destinationY
        : 0
    const destinationX =
      coordinates.originX + coordinates.destinationX > 0
        ? coordinates.destinationX
        : 0
    let loop = true
    for (let index = 0; index < numberOfRetries && loop; index++) {
      if (await checkElement.isDisplayed()) {
        loop = false
      } else {
        driver
          .action('pointer', {
            parameters: { pointerType: 'touch' },
          })
          .move(coordinates.originX, coordinates.originY)
          .pause(300)
          .move(destinationX, destinationY)
          .perform()
      }
    }
  }
}

When I run the tests, I am seeing the following error:

[0-1] Error in "0: Then I should see the Priority banner"
invalid element state: Unable to perform W3C actions. Check the logcat output for possible error reports and make sure your input actions chain is valid.

I would appreciate any help or guidance.

1 Like

Did you get an answer, what logcat filters are people using? Logcat is super noisy and knowing what we are filtering for would be really useful here.

I really hope this next bit helps the next person. This Python code was raising an ElementInvalidState exception for me, I ended up putting it into an try-catch and ignoring the problem in the end.

ac = ActionChains(self.ui.driver) try: ac.move_to_element(element_parent()).move_by_offset(0, int(size['height']/4)).click_and_hold().\ move_by_offset(0, -int(size['height']/4)).release().perform() except Exception as ex: PageObject.log.log(f"swipe_up_to_entry() handled a {type(ex).__name__}")

This was after I did work out roughly how to logcat, the trace however made me none the wizer at all, but hope it helps the next visitor a tiny bit. All I can surmise is that the release() is raising an exception for some reason, because the finger drag is not doing anything unusual, it’s still well within the screen and element bounds as I finger-scroll a short list. I did however find that the logcat at least reveals the co-ordinates, but other than that, it was a slightly un-helpful error message.

adb shell “logcat | grep appium”

05-13 18:52:04.496 13462 13520 I appium : [41109646 (success)] Synthesized: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=540.0, y[0]=1356.333, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=41109646, downTime=41109426, deviceId=0, source=0x1002, displayId=0, eventId=-854393961 } 05-13 18:52:04.518 13462 13520 I appium : [41109666 (success)] Synthesized: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=540.0, y[0]=1314.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=41109666, downTime=41109426, deviceId=0, source=0x1002, displayId=0, eventId=-734318226 } 05-13 18:52:04.549 13462 13520 I appium : [41109687 (success)] Synthesized: MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=540.0, y[0]=1314.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=41109687, downTime=41109426, deviceId=0, source=0x1002, displayId=0, eventId=-1015732580 } 05-13 18:52:04.550 13462 13520 I appium : The event has been delayed for 22ms 05-13 18:52:04.556 13462 13520 I appium : AppiumResponse: {"sessionId":"1326f879-90c3-4210-b71a-7d27301733ba","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.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)\n\tat io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)\n\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)\n\tat io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)\n\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)\n\tat io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)\n\tat java.lang.Thread.run(Thread.java:1012)\n"}}