Appium - When do we use touch action? Could I have actual example for inputing text with it?

appium touch action swipe example
how to get x y coordinates in appium
vertical swipe in appium
appium move to element
appium swipe left
touchaction appium python
double tap in appium
touchaction is a raw type. references to generic type touchaction<t> should be parameterized

I would like to ask when do we use touch action in Appium. I also want to ask: could we use touch action to tap/press the android.widget.EditText element and sendKeys to it. Could I have an workable example to test it?

We use touch action whenever we want to click/tap on the particular element on the device.

For Clicking

You can use touch action for EditText element as bewlow :

driver.findElement(By.xpath("your element xpath/id")).click();

For Typing

Also, You can use sendKeys for EditText Element as below : This internal clicks on the element, clears the text and types the string that you are sending.

driver.findElement(By.xpath("your element xpath/id")).sendKeys("textToBeTyped");

OR

You can click and send keys separately without clearing the existing text inside the text element as below :

driver.findElement(By.xpath("your element xpath/id")).click();
driver.getKeyboard().sendKeys(textToBeTyped);

Touch Actions, appium.io › docs › commands › interactions › touch › tap Here's an example of creating an action in pseudocode: TouchAction().press(el0).moveTo(el1).release() The above simulates a user pressing down on an element, sliding their finger to another position, and removing their finger from the screen. Appium performs the events in sequence. You can add a wait event to control the timing of the gesture.

1.public void tap(int fingers, int x, int y, int duration) {
        appiumDriver.tap(fingers, x, y, duration);
    }

2. public   void swipe(int startx, int starty, int endx,int endy,int duration)
    {
        TouchAction touchAction = new TouchAction(appiumDriver);
        System.out.println(startx+" "+starty);
        System.out.println("Entering swipe");

            System.out.println("Swipe from "+startx +" " +starty +"to" +endx +" " +endy );
            touchAction.press(startx, starty).waitAction(duration).moveTo(endx,endy).release().perform();
    }

3. public void longClick(String element, int index, int clickCount, int X, int Y) {
    WebElement webElement = appiumDriver.findElement(By.xpath(element));

        TouchAction Action = new TouchAction(appiumDriver);
        Action.longPress(webElement).release().perform();

    }

4. public void drag( String element, int index, int xOffset, int yOffset) {
        WebElement webElement = appiumDriver.findElement(By.xpath(element));
        TouchAction drag=new TouchAction(appiumDriver);

        int startX=webElement.getLocation().getX();
        int startY=webElement.getLocation().getY();

        System.out.println("startX: "+startX+" startY: "+startY);
        drag.press(startX,startY).moveTo(xOffset,yOffset).release().perform();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

Touch Perform, Example Usage. Java; Python; Javascript; Ruby; C#; PHP. TouchActions action = new TouchActions(driver); action.singleTap(element); action.perform();. 'Touch Perform' works similarly to the other singular touch interactions, except that this allows you to chain together more than one touch action as one command. This is useful because Appium commands are sent over the network and there's latency between commands.

Single Tap, You can instantiate it into your BaseScreen or BasePage class and use it in your Screen/Page classes. I will start with the MobileActions class. By  Sometimes using the standard Action APIs leads to undesired behavior due to the not-always-perfect mapping between the WebDriver spec and the available mobile automation technologies Appium uses. That's why Appium also makes platform-specific action methods available for 'direct' access to underlying action automation methods.

Appium Mobile Actions | Swipe | Tap | MultiTouch, findElement(By.id("io.appium.android.apis:id/drag_text")); assertEquals("Drag text not empty", "", dragText.getText()); TouchAction dragNDrop = new  This Video contains how can we automate Long Press using Touch Action Class. You can download discussed code from given url : https://github.com/freeautomati

io.appium.java_client.TouchAction.perform java code examples , Classic examples would be ride hailing, food delivery, or chat apps. In this edition we take a look at how you can use Appium for all your RPA needs. For real iOS devices, the typical commands to get content from the device clipboard of the W3C Actions API that allows the encoding of arbitrary touch input behavior. We have always issue with handling date time picker in appium even there is no proper solution in appium forum. I would request to check and provide solution how we can deal with . Ex. While entering date of birth and we are into year field we have scroll up till past year. Scroll down to certain number which is not visible that point of time.

All Editions, For full documentation of Appium, with more examples in popular Although Appium can test websites on a mobile device, it is more Perform an action on the element (e.g. tap the login button). Practically, you have three options. When testing on desktop browsers, you can also use Sauce Storage  1 Appium - When do we use touch action? Could I have actual example for inputing text with it? Could I have actual example for inputing text with it? Feb 21 '17

Comments
  • is below solution working?
  • Not exactly. I could find a button to click, however there is other's problem, I can't sendKeys to a textField: stackoverflow.com/questions/42271992/… I can get the keyboard, but I can't sendKeys because the elements are never be clicked.
  • Can you use last two lines of code in the below answer? That should resolve your problem. Don't send keys directly to element. Just click on that and then use driver.getKeyboard().sendKeys("textToBeTyped");
  • There does an element click, but not on the element I choose. After all the testing, I find that it directly click using the driver, but not by the xpath
  • driver finds the element using xpath only and then clicks.