How to use touch action in new java client 6.0.0-BETA4

Why do you have this capability:
dc.setCapability(“BROWSER_NAME”, “android”);?
deviceName, platformName, platformVersion would be suitable.
And try to use my example provided above

im taking the same prob, using AndroidDriver or RemoteWebDriver, i cant use TouchAction…

I see method

tap(WebElement el) has been removed from Appium Java Client 6.x onwards.

Are you aware of any specific reasons ? Certainly this method is more useful and readable than newer methods using TapOptions and PointOptions. :thinking:

Could you please share us, LongPress on coordinates with duration? I have tried but I can’t. What I have tried

//LongPress on coordinates with duration:
new TouchAction((AndroidDriver)driver).longPress(longPressOptions().withElement((ElementOption) point(xPoint, yPoint)).withDuration(Duration.ofMillis(duration))).release().perform();

1 Like

dude,
I searched for every fck place on the internet and 3 days looking I find your code !! thx man !!! help me a lot

hi,

Swipe not working with co ordinates and press pointoption.
Using java-client-7.0.0

Can you please help me.

Please find the code and log below.


public class Unit3 {

public static void main(String[] args) throws MalformedURLException {
	// TODO Auto-generated method stub
	
	File appDir = new File("src");
	File appName = new File(appDir, "ApiDemos-debug.apk");
	
	DesiredCapabilities capability = new DesiredCapabilities();
	capability.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus6");
	capability.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
	capability.setCapability(MobileCapabilityType.APP, appName.getAbsolutePath());
	
	AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),capability);
	driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
	
	driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();
	
    boolean flag = true;
	
	do
    {			
        TouchAction touch = new TouchAction(driver);                   
              
		
		Dimension size = driver.manage().window().getSize();
		int startx = size.getWidth()/2;
		int endx = size.getWidth()/2;
		int starty = (int)(size.getHeight()* 0.80);
		int endy = (int)(size.getHeight()* 0.10);	
		touch.press(PointOption.point(startx, starty)).waitAction().moveTo(PointOption.point(endx, endy)).release().perform();
		
        List<AndroidElement> ls = driver.findElementsByClassName("android.widget.TextView");
        for(int i=0;i<ls.size();i++)
        {
        	 if(ls.get(i).getText().contains("Seek")){
        		 touch.tap(tapOptions().withElement(element(ls.get(i)))).perform();
        		 flag=false;
  			     break; 		
                	 }
        }   			
						
    }while(flag=true);     	
}


}

[HTTP] <-- GET /wd/hub/session/353eb1f7-d777-4c51-b723-a7685d8eec19/window/rect 200 37 ms - 50

[HTTP]

[HTTP] --> POST /wd/hub/session/353eb1f7-d777-4c51-b723-a7685d8eec19/touch/perform

[HTTP] {“actions”:[{“action”:“press”,“options”:{“x”:720,“y”:1913}},{“action”:“wait”,“options”:{}},{“action”:“moveTo”,“options”:{“x”:720,“y”:239}},{“action”:“release”,“options”:{}}]}

[debug] [W3C (353eb1f7)] Calling AppiumDriver.performTouch() with args: [[{“action”:“press”,“options”:{“x”:720,“y”:1913}},{“action”:“wait”,“options”:{}},{“action”:“moveTo”,“options”:{“x”:720,“y”:239}},{“action”:“release”,“options”:{}}],“353eb1f7-d777-4c51-b723-a7685d8eec19”]

[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“swipe”,“params”:{“startX”:720,“startY”:1913,“endX”:720,“endY”:239,“steps”:22}}

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getDeviceSize

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:0,“value”:{“height”:2392,“width”:1440}}

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“swipe”,“params”:{“startX”:720,“startY”:1913,“endX”:720,“endY”:239,“steps”:22}}

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: swipe

[debug] [AndroidBootstrap] Received command result from bootstrap

[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError

[debug] [W3C (353eb1f7)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: The swipe did not complete successfully

[debug] [W3C (353eb1f7)] at errorFromMJSONWPStatusCode (C:\Users\sures\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:789:10)

[debug] [W3C (353eb1f7)] at Socket.socketClient.on.data (C:\Users\sures\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\bootstrap.js:139:18)

[debug] [W3C (353eb1f7)] at Socket.emit (events.js:189:13)

[debug] [W3C (353eb1f7)] at addChunk (_stream_readable.js:284:12)

[debug] [W3C (353eb1f7)] at readableAddChunk (_stream_readable.js:261:13)

[debug] [W3C (353eb1f7)] at Socket.Readable.push (_stream_readable.js:220:10)

[debug] [W3C (353eb1f7)] at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

[HTTP] <-- POST /wd/hub/session/353eb1f7-d777-4c51-b723-a7685d8eec19/touch/perform 500 76 ms - 927

[HTTP]

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2392]

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2392]

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Swiping from [x=720.0, y=1913.0] to [x=720.0, y=239.0] with steps: 22[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:13,“value”:“The swipe did not complete successfully”}

[debug] [AndroidBootstrap] Emitting alert message…

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Emitting system alert message

@Telmo_Cardoso can you tell me how to find out coordinate or scroll horizontal and click element.
i’m using intellij and i’m not getting getElement.

sky if possible.

skype id : chetan thummar

Hi @anu_suryey,
you can try the below mentioned method

public void StoAndroidMobile(By strobj1,By strobj2)

{

try {

boolean isFoundTheElement_1 = driver.findElements(strobj1).size() > 0;

boolean isFoundTheElement_2 = driver.findElements(strobj2).size() > 0;

while (isFoundTheElement_1 == true || isFoundTheElement_2 == true){

Dimension sizes_1 = driver.findElement(strobj1).getSize();

Dimension sizes_2 = driver.findElement(strobj2).getSize();

int obj1_height = sizes_1.getHeight();

int obj1_width = sizes_1.getWidth();

int obj2_height = sizes_2.getHeight();

int obj2_width = sizes_2.getWidth();

System.out.println(sizes_2);

new TouchAction(AndroidDriver).press(PointOption.point(obj1_width, obj1_height).waitAction().moveTo(PointOption.point(obj2_width, obj2_height)).release().perform();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

-Peace out !
Thiru

Hello

My code don’t click with coordinates.

package br.alex.appium.page;

import static br.alex.appium.core.DriverFactory.getDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.touch.TouchActions;

import br.alex.appium.core.BasePage;
import br.alex.appium.core.DriverFactory;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.TapOptions;
import io.appium.java_client.touch.offset.ElementOption;

public void clicarBotaoMais() {
	MobileElement botao = getDriver().findElement(By.xpath("//*[@text='(+)']"));

	new TouchAction(getDriver())
		.tap(TapOptions.tapOptions()
		.withElement(ElementOption.element(botao, -500, -100)))
		.release()
		.perform();

}

Can we help-me?

Alex Borelli

Hello guys,
trying to excute the following two commands:

new TouchAction(driver).longPress(753, 1483).moveTo(626, 503).release().perform();

new TouchAction(driver).longPress(753, 1483).waitAction(Duration.ofMillis(672)).moveTo(626, 503).release().perform();

but getting the following problems in eclipse:

The method longPress(LongPressOptions) in the type TouchAction is not applicable for the arguments

and following warning

TouchAction is a raw type. References to generic type TouchAction should be parameterized

Could you suggest how to re-write the commmands with Appium 6 please ?

Thanks a lot,
Giuseppe