Unknown command : touch/perform

Hi,
After some try with the php-client, I switch to the java client as I’m facing an error when using swipe.

But now with the Java Client, I’m facing a new error :

info: JSONWP Proxy: Proxying [POST /wd/hub/session/345e96ea-ed74-4338-b9fe-b4cf5389fada/element/0.8161357417702675-3/click] to [POST http://127.0.0.1:9515/wd/hub/session/7a2178f9915a999606c4e61321149e8f/element/0.8161357417702675-3/click] with body: {“id”:“0.8161357417702675-3”}
info: JSONWP Proxy: Got response with status 200: {“sessionId”:“7a2178f9915a999606c4e61321149e8f”,“status”:0,“value”:null}
info: JSONWP Proxy: Replacing sessionId 7a2178f9915a999606c4e61321149e8f with 345e96ea-ed74-4338-b9fe-b4cf5389fada
info: ← POST /wd/hub/session/345e96ea-ed74-4338-b9fe-b4cf5389fada/element/0.8161357417702675-3/click 200 570.358 ms - 76
info: → POST /wd/hub/session/345e96ea-ed74-4338-b9fe-b4cf5389fada/touch/perform {“actions”:[{“action”:“tap”,“options”:{“element”:“0.8161357417702675-3”}}]}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/345e96ea-ed74-4338-b9fe-b4cf5389fada/touch/perform] to [POST http://127.0.0.1:9515/wd/hub/session/7a2178f9915a999606c4e61321149e8f/touch/perform] with body: {“actions”:[{“action”:“tap”,“options”:{“element”:“0.8161357417702675-3”}}]}
info: JSONWP Proxy: Got response with status 404: unknown command: session/7a2178f9915a999606c4e61321149e8f/touch/perform
info: ← POST /wd/hub/session/345e96ea-ed74-4338-b9fe-b4cf5389fada/touch/perform 404 3.667 ms - 73

Maybe i’m wrong in the code :

WebElement btn = driver.findElement(By.className(“test-synctrackImg”));
btn.click(); // Just for test …
TouchAction ta = new TouchAction(driver);
ta.tap(btn);

Info :

  • Application : hybrid
  • Target : Android 5.1 - real device
  • Appium : 1.4.8
  • client : 3.3.0
  • selenium java : 2.52.0

Was working fine with php

Thanks.

you cant use TouchAction class on webelement…you have to change it to mobile element.

Hi,
Thanks for the return but It seems that it doesn’t work … For info, my app is an Hybrid App.

Here is the new code :

import io.appium.java_client.MobileElement;
// In the BeforeTest
[…]
// Change from WebElement to MobileElement
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),cap);
[…]
// In the test method :
System.out.println(“recordAgent() :: get boutton”);
MobileElement btn = driver.findElement(By.className(“connectionBtn”));
System.out.println(“recordAgent() :: click (just for test)”);
btn.click();
System.out.println(“recordAgent() :: Create TA”);
TouchAction ta = new TouchAction(driver);
System.out.println(“recordAgent() :: Before Tap”);
ta.tap(btn);
System.out.println(“recordAgent() :: After Tap”);

The trace log of the test :

recordAgent() :: get boutton
recordAgent() :: click (just for test)
recordAgent() :: Create TA
recordAgent() :: Before Tap
recordAgent() :: After Tap

The appium log :

info: JSONWP Proxy: Proxying [POST /wd/hub/session/c40f4bf9-86cc-4ddf-9eb0-096fd080df28/element] to [POST http://127.0.0.1:9515/wd/hub/session/b332a3f05703c8ca2cc9eb52ae7a6f2e/element] with body: {“using”:“class name”,“value”:“connectionBtn”}
info: JSONWP Proxy: Got response with status 200: {“sessionId”:“b332a3f05703c8ca2cc9eb52ae7a6f2e”,“status”:0,“value”:{“ELEMENT”:“0.7732987280469388-3”}}
info: JSONWP Proxy: Replacing sessionId b332a3f05703c8ca2cc9eb52ae7a6f2e with c40f4bf9-86cc-4ddf-9eb0-096fd080df28
info: ← POST /wd/hub/session/c40f4bf9-86cc-4ddf-9eb0-096fd080df28/element 200 556.144 ms - 106
info: → POST /wd/hub/session/c40f4bf9-86cc-4ddf-9eb0-096fd080df28/element/0.7732987280469388-3/click {“id”:“0.7732987280469388-3”}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/c40f4bf9-86cc-4ddf-9eb0-096fd080df28/element/0.7732987280469388-3/click] to [POST http://127.0.0.1:9515/wd/hub/session/b332a3f05703c8ca2cc9eb52ae7a6f2e/element/0.7732987280469388-3/click] with body: {“id”:“0.7732987280469388-3”}
info: JSONWP Proxy: Got response with status 200: {“sessionId”:“b332a3f05703c8ca2cc9eb52ae7a6f2e”,“status”:0,“value”:null}
info: JSONWP Proxy: Replacing sessionId b332a3f05703c8ca2cc9eb52ae7a6f2e with c40f4bf9-86cc-4ddf-9eb0-096fd080df28
info: ← POST /wd/hub/session/c40f4bf9-86cc-4ddf-9eb0-096fd080df28/element/0.7732987280469388-3/click 200 1396.000 ms - 76
info: → DELETE /wd/hub/session/c40f4bf9-86cc-4ddf-9eb0-096fd080df28 {}
info: Shutting down appium session

From what I undestand, the “tap” action is not send to appium …

Hi,
Still facing the issue … any help ?

You can use WebElement for TouchAction, as the TouchAction API is defined to accept WebElement objects.

What you’re missing is calling the perform() method on the TouchAction object. Check the Javadocs: http://appium.github.io/java-client/io/appium/java_client/TouchAction.html

As an example:

WebElement elem = blah blah blah...
TouchAction act = new TouchAction(driver);
act.tap(elem);
act.perform();

If you prefer, you can switch the code style to use the “chain” style:

act.tap(elem).perform();

Thanks for the help but I’m still facing the problem.
Is there something special to include or setup to have access to TouchApi ?

I switch back to to WebElemet and here the trace log from appium :

info: JSONWP Proxy: Proxying [POST /wd/hub/session/1b9aa654-6d65-47df-96a6-18382a8d14ca/element] to [POST http://127.0.0.1:9515/wd/hub/session/309856b9644d5a5a49eeba3ee5cff7cc/element] with body: {“using”:“class name”,“value”:“connectionBtn”}
info: JSONWP Proxy: Got response with status 200: {“sessionId”:“309856b9644d5a5a49eeba3ee5cff7cc”,“status”:0,“value”:{“ELEMENT”:“0.5542848368640989-3”}}
info: JSONWP Proxy: Replacing sessionId 309856b9644d5a5a49eeba3ee5cff7cc with 1b9aa654-6d65-47df-96a6-18382a8d14ca
info: ← POST /wd/hub/session/1b9aa654-6d65-47df-96a6-18382a8d14ca/element 200 244.478 ms - 106
info: → POST /wd/hub/session/1b9aa654-6d65-47df-96a6-18382a8d14ca/element/0.5542848368640989-3/click {“id”:“0.5542848368640989-3”}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/1b9aa654-6d65-47df-96a6-18382a8d14ca/element/0.5542848368640989-3/click] to [POST http://127.0.0.1:9515/wd/hub/session/309856b9644d5a5a49eeba3ee5cff7cc/element/0.5542848368640989-3/click] with body: {“id”:“0.5542848368640989-3”}
info: JSONWP Proxy: Got response with status 200: {“sessionId”:“309856b9644d5a5a49eeba3ee5cff7cc”,“status”:0,“value”:null}
info: JSONWP Proxy: Replacing sessionId 309856b9644d5a5a49eeba3ee5cff7cc with 1b9aa654-6d65-47df-96a6-18382a8d14ca
info: ← POST /wd/hub/session/1b9aa654-6d65-47df-96a6-18382a8d14ca/element/0.5542848368640989-3/click 200 511.063 ms - 76
info: → POST /wd/hub/session/1b9aa654-6d65-47df-96a6-18382a8d14ca/touch/perform {“actions”:[{“action”:“tap”,“options”:{“element”:“0.5542848368640989-3”}}]}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/1b9aa654-6d65-47df-96a6-18382a8d14ca/touch/perform] to [POST http://127.0.0.1:9515/wd/hub/session/309856b9644d5a5a49eeba3ee5cff7cc/touch/perform] with body: {“actions”:[{“action”:“tap”,“options”:{“element”:“0.5542848368640989-3”}}]}
info: JSONWP Proxy: Got response with status 404: unknown command: session/309856b9644d5a5a49eeba3ee5cff7cc/touch/perform
info: ← POST /wd/hub/session/1b9aa654-6d65-47df-96a6-18382a8d14ca/touch/perform 404 13.778 ms - 73

I’ve also tried with the MobileElement and same result ?
> info: JSONWP Proxy: Got response with status 404: unknown command: session/f330a6634c55c68255ed5e0a1d8e51df/touch/perform

info: ← POST /wd/hub/session/29b671ba-5327-45e6-ad68-78887350ffce/touch/perform 404 15.659 ms - 73

Thanks again for any help

Hmm… that’s really interesting. I’ll have to try this myself to see what happens.

You said this was working fine with PHP. Can you post Appium’s output when you try this same action with PHP?

Hi,
I’ve no access to php log until monday …What I can say is I’m able to use the tap() method on element without error. But I’m not able to use the swipe method. By memory, I think I’ve the same type of message …

Thanks for your help

Hi,
As you ask, I’m made test on php. First, here is the code :

$this->byId(CONNEXION_FORM_SUBMIT)->tap();

Here is the log :

info: JSONWP Proxy: Proxying [POST /wd/hub/session/7ea983a9-20e4-4d5b-8dd9-f3eb10a490dd/element] to [POST http://127.0.0.1:9515/wd/hub/session/5b6cddf3aa22e0d1087bf5c7cc155ccb/element] with body: {“using”:“id”,“value”:“ext-button-68”}
info: JSONWP Proxy: Got response with status 200: {“sessionId”:“5b6cddf3aa22e0d1087bf5c7cc155ccb”,“status”:0,“value”:{“ELEMENT”:“0.6501863966695964-3”}}
info: JSONWP Proxy: Replacing sessionId 5b6cddf3aa22e0d1087bf5c7cc155ccb with 7ea983a9-20e4-4d5b-8dd9-f3eb10a490dd
info: ← POST /wd/hub/session/7ea983a9-20e4-4d5b-8dd9-f3eb10a490dd/element 200 92.445 ms - 106
info: → POST /wd/hub/session/7ea983a9-20e4-4d5b-8dd9-f3eb10a490dd/touch/click {“element”:“0.6501863966695964-3”}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/7ea983a9-20e4-4d5b-8dd9-f3eb10a490dd/touch/click] to [POST http://127.0.0.1:9515/wd/hub/session/5b6cddf3aa22e0d1087bf5c7cc155ccb/touch/click] with body: {“element”:“0.6501863966695964-3”}
info: JSONWP Proxy: Got response with status 200: {“sessionId”:“5b6cddf3aa22e0d1087bf5c7cc155ccb”,“status”:0,“value”:null}
info: JSONWP Proxy: Replacing sessionId 5b6cddf3aa22e0d1087bf5c7cc155ccb with 7ea983a9-20e4-4d5b-8dd9-f3eb10a490dd

Thanks to your note, I notice that even the code is doing a tap, in the log, is doing a click.

I’ve try again in Java :

info: → POST /wd/hub/session/a9a81861-19f1-4da9-bd77-d0024bc9e30f/touch/perform {“actions”:[{“action”:“tap”,“options”:{“element”:“0.27384524676017463-3”}}]}
info: JSONWP Proxy: Proxying [POST /wd/hub/session/a9a81861-19f1-4da9-bd77-d0024bc9e30f/touch/perform] to [POST http://127.0.0.1:9515/wd/hub/session/93a73599ec76c2bebe55d028aa7247ce/touch/perform] with body: {“actions”:[{“action”:“tap”,“options”:{“element”:“0.27384524676017463-3”}}]}
info: JSONWP Proxy: Got response with status 404: unknown command: session/93a73599ec76c2bebe55d028aa7247ce/touch/perform

I just tried TouchAction on my end with your setup (except my device is 4.4.4, but I don’t think that should matter here). TouchAction is working fine on my end, so I’m still not quite sure what’s happening on your end.

Here’s a quick workaround for the tap issue, however. Instead of using TouchActions to tap on your element, you can call the .click() method on your element directly.

WebElement elem = ...;
elem.click();

You can use driver.swipe for your swiping problem if you need to as well.

I have some separate questions for you to figure out what’s happening with the TouchAction API however. Are you running Appium from source, or are you using the pre-packaged NPM package? If you’re using it from source, did you remember to run the reset.sh script with the --android flag?

Hi,
Again : many thanks for your help … I think I’ve a A 4 somewhere so I will try tomorrow.

I’ve already try the click method but no results. I guess that the code is waiting for a tap and not click …

As far as I remember, I use the NPM package …

I’m on linux virtual machine ? Any chance that there is an impact.

I’m bit blocked as :

  • java : cannot do a tap
  • php : swipe is not working …

In noth case, the trouble comes from touch api … may I should install on other system manually ?

Hi,
Back again …

I’ve try on windows with the same version and code … same error …

Ah, I was finally able to reproduce this error. It seems I forgot about the all-important context that Appium is running in. I was able to generate this error by running in a WebView context and then trying to run a TouchAction command. It seems that for this version of Appium, TouchActions are not implemented in a webview context (hybrid applications have this context).

If you need to tap on something in a web view context, you’re stuck with using WebElement.click().

You still have the option of switching to the native application context and then performing TouchActions in the native context. You can query and switch contexts using getContextHandles() and context().

Hi,
Ok … the thing is I need to swipe (to select date) and in Java click is not working … Do you know if there is a plan to support TouchAction on WebViews ?

Other question : how can I get say how to Tap or swipe in native context as I cannot find element ? Is there a way to get an WebElement in Native ?

Thanks again for all your help.

I’m not too sure if there is a plan to support TouchAction in WebViews. I haven’t checked the latest version of Appium yet (1.5.0), so I’m not sure if they were implemented or not.

In all cases I’ve seen, you should still be able to retrieve web elements even within a native context. The main difference is that the elements will be represented as Android native elements e.g. text will be represented as android.widget.TextViews, images will be android.widget.ImageViews, etc. Some attributes from the HTML source will be mapped to their equivalent attributes in Android’s XML e.g. the “alt” attribute for <img…> tags will display as “content-desc” in the Android XML source. You’ll have to retrieve the elements as if you were working in a native context, and not a web context however.

I’m not knowledgeable about hybrid applications, so perhaps @Christopher_Graham might have better insight for you. :slight_smile:

Ok !
Again : thanks for you help !

I’ll try to send a message to @Christopher_Graham

Have a nice day.

I’m flattered someone thought I’d know the answer. :slight_smile:

I haven’t personally worked on any code to scroll in webview at this time (still need to tackle that). But this is my Python code to scroll in native view. Hope this helps.

# switch to your webview context before proceeding
element_to_tap = <your code to successfully locate this element>
element_to_drag_to = <your code to successfully locate this element>
# Set swipe_time to something long for a clean scroll, faster for a flick which will overshoot your element_to_drag_to
swipe_time = 4000
self.driver.swipe(element_to_tap.location["x"],
                  element_to_tap.location["y"],
                  element_to_drag_to.location["x"],
                  element_to_drag_to.location["y"],
                  swipe_time)

Hi Thanks for your help !

So here is what I try : switch back to native and swipe :

info: [debug] Pushing command to appium work queue: [“swipe”,“startX”:150,“startY”:1000,“endX”:150,“endY”:1100,“steps”:112}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“swipe”,“params”:{“startX”:150,“startY”:1000,“endX”:150,“endY”:1100,“steps”:112}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: swipe
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1080,1776]
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1080,1776]
info: [debug] [BOOTSTRAP] [debug] Swiping from [x=150.0, y=1000.0] to [x=150.0,y=1100.0] with steps: 112
info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:true}
info: [debug] Responding to client with success: {“status”:0,“value”:true,“sessionId”:“28ae7c1a-b90b-4358-a1fe-5d1cde5163bb”}

So it seems that command is weel accepted but the here is nothing changing on my screen.

I do not know if the problem comes from the coordonate or the fact that element are in the web view…

I switch back to php client as tap is not working in php …

==> How can I know the coordinate for a swipe ? My goal is to select a date in datepickerwheel ?

Finding coordinates for a swipe is a separate problem. I will classify the problem as two separate groups of problems:

  1. Swipes that depend on the position of a particular UI element.
  2. Swipes that do not depend on the position of a particular UI element.

For swipes that depend on the position of a UI element, you are usually starting a swipe starting from the UI element’s position. You can retrieve the position of the upper-left corner of the UI element by calling WebElement.getPosition(). This should return a Point object that contains the (x,y) coordinates of that corner.

For swipes that do not depend on the position of the UI element, you are usually starting and ending your swipe based on your screen (e.g. swiping from the bottom of the screen all the way to the top of the screen). For this, you can query the size of the screen by calling WebDriver.manage().options().window().getSize(), which will return a Dimension object containing the size of the screen.

Swiping, then, is just performing TouchActions (or using driver.swipe() for convenience) with the coordinates you retrieved and processed from Dimensions or Points.


A few notes: The positive y-axis points down on the screen. The origin of the device’s xy-plane is located at the upper left-hand corner of your device. From your code you just pasted, this means that you are swiping from the top to the bottom, meaning you’re trying to scroll the screen up. If you are at the top of the screen, then this should do nothing for most applications. If you know about the right-hand rule, this means your thumb (the positive z-axis) points into the screen.

Other notes: If your date picker is an Android native date picker, you can probably make it easier by clicking on the buttons available in the date picker, or typing in the dates for the individual fields, at least on devices with system versions older than Android 5.0. If your date picker is a completely custom date picker, you’ll have to share some information about this date picker.

Hi,
Again : many thanks for your help.

First good news : I’m to do a swap on a list by passing to Native Context,
Second good news : I’ve the size of my screen,
Third good news : i’m able to swipe on the DatePicker :joy: !!!

Next step : swipe a good date and save it !

Thanks again !

1 Like