Long press not working

  • Platform : Android
  • Appium version: 1.17.1
  • Test Execution : Emulator
  • The language you are using for writing tests (client binding):Java
  • Your OS: macOS Catalina

I’m using the below method to perform long press action:
public void touchAndHold(MobileElement mobileElement){
try{
new TouchAction(androidDriver).longPress(LongPressOptions.longPressOptions().
withElement(ElementOption.element(mobileElement))).
waitAction(waitOptions(ofMillis(500))).perform();
}
catch (Exception e){
LOGGER.info(“Unable to long press”);
e.printStackTrace();
}
}

Getting the below error while using this method : Encountered internal error running command: io.appium.uiautomator2.common.exceptions.InvalidArgumentException: com.google.gson.JsonSyntaxException:

Logs:

[debug] [W3C (681b062d)] Calling AppiumDriver.performTouch() with args: [[{“action”:“longPress”,“options”:{“element”:“a54a7bf8-ded8-4b4b-9263-49c8707e093e”}}],“681b062d-3508-48e4-9b12-b784d5587154”]
[UiAutomator2] calling get location: a54a7bf8-ded8-4b4b-9263-49c8707e093e
[debug] [WD Proxy] Matched ‘/element/a54a7bf8-ded8-4b4b-9263-49c8707e093e/location’ to command name ‘getLocation’
[debug] [WD Proxy] Proxying [GET /element/a54a7bf8-ded8-4b4b-9263-49c8707e093e/location] to [GET http://127.0.0.1:8200/wd/hub/session/d6eb0001-5b3c-428b-8eb5-4e12d355d6e7/element/a54a7bf8-ded8-4b4b-9263-49c8707e093e/location] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“d6eb0001-5b3c-428b-8eb5-4e12d355d6e7”,“value”:{“x”:91,“y”:713}}
[debug] [WD Proxy] Matched ‘/element/a54a7bf8-ded8-4b4b-9263-49c8707e093e/size’ to command name ‘getSize’
[debug] [WD Proxy] Proxying [GET /element/a54a7bf8-ded8-4b4b-9263-49c8707e093e/size] to [GET http://127.0.0.1:8200/wd/hub/session/d6eb0001-5b3c-428b-8eb5-4e12d355d6e7/element/a54a7bf8-ded8-4b4b-9263-49c8707e093e/size] with no body
[debug] [WD Proxy] Got response with status 200: {“sessionId”:“d6eb0001-5b3c-428b-8eb5-4e12d355d6e7”,“value”:{“height”:77,“width”:396}}
[debug] [WD Proxy] Matched ‘/touch/down’ to command name ‘touchDown’
[debug] [WD Proxy] Proxying [POST /touch/down] to [POST http://127.0.0.1:8200/wd/hub/session/d6eb0001-5b3c-428b-8eb5-4e12d355d6e7/touch/down] with body: {“params”:{“element”:null,“x”:289,“y”:751.5}}
[WD Proxy] Got response with status 400: {“sessionId”:“d6eb0001-5b3c-428b-8eb5-4e12d355d6e7”,“value”:{“error”:“invalid argument”,“message”:“com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 751.5 at line 1 column 44 path $.params.y”,“stacktrace”:"io.appium.uiautomator2.common.exceptions.InvalidArgumentException: com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 751.5 at line 1 column 44 path $.params.y\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:47)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:257)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:247)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:50)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerCo…
[debug] [W3C] Matched W3C error code ‘invalid argument’ to InvalidArgumentError
[debug] [W3C (681b062d)] Encountered internal error running command: io.appium.uiautomator2.common.exceptions.InvalidArgumentException: com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 751.5 at line 1 column 44 path $.params.y
[debug] [W3C (681b062d)] at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:47)
[debug] [W3C (681b062d)] at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:257)
[debug] [W3C (681b062d)] at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:247)
[debug] [W3C (681b062d)] at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:50)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
[debug] [W3C (681b062d)] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
[debug] [W3C (681b062d)] at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
[debug] [W3C (681b062d)] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
[debug] [W3C (681b062d)] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
[debug] [W3C (681b062d)] at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
[debug] [W3C (681b062d)] at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
[debug] [W3C (681b062d)] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[debug] [W3C (681b062d)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[debug] [W3C (681b062d)] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
[debug] [W3C (681b062d)] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
[debug] [W3C (681b062d)] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
[debug] [W3C (681b062d)] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
[debug] [W3C (681b062d)] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
[debug] [W3C (681b062d)] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
[debug] [W3C (681b062d)] at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
[debug] [W3C (681b062d)] at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
[debug] [W3C (681b062d)] at java.lang.Thread.run(Thread.java:764)
[debug] [W3C (681b062d)] Caused by: com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 751.5 at line 1 column 44 path $.params.y
[debug] [W3C (681b062d)] at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:228)
[debug] [W3C (681b062d)] at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:218)
[debug] [W3C (681b062d)] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
[debug] [W3C (681b062d)] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
[debug] [W3C (681b062d)] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
[debug] [W3C (681b062d)] at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
[debug] [W3C (681b062d)] at com.google.gson.Gson.fromJson(Gson.java:932)
[debug] [W3C (681b062d)] at com.google.gson.Gson.fromJson(Gson.jJul 22, 2020 4:01:57 PM
INFO: Unable to long press
org.openqa.selenium.InvalidArgumentException: com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 751.5 at line 1 column 44 path $.params.y
[debug] [W3C (681b062d)] at com.google.gson.Gson.fromJson(Gson.java:846)
[debug] [W3C (681b062d)] at com.google.gson.Gson.fromJson(Gson.jav at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)a:817)
[debug] [W3C (681b062d)] at io.appium.uiautomator2.utils.ModelUtils.toModel(ModelUtils.java:17)
[debug] [W3C (681b06
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
2d)] at io.appium.uiautomator2.handler.BaseTouchAction.safeHandle(BaseTouchAction.java:51)
[debug] [W3C (681b062d)] at io.appium.uiautoma at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.PerformsTouchActions.performTouchAction(PerformsTouchActions.java:41)
tor2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:41)
[debug] [W3C (681b062d)] … 33 more
[debug] [W3C (681b062d)] Caused by: java.lang.NumberFormatException: Expected an int but was 751.5 at line 1 at io.appium.java_client.TouchAction.perform(TouchAction.java:187)
[debug] [W3C (681b062d)] at com.google.gson.stream.JsonReader.nextInt(JsonReader.java:1205)
[debug]
at
at Execution.cvs.CvsProviderTests.cvsProviderSearchAboutAndLocation(CvsProviderTests.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
[W3C (681b062d)] at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:226)
[debug] [W3C ( at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
681b062d)] … 45 more