Appium-Cookbook
  • Appium
  • Set-up
    • Installation
    • java-client
  • Recipes
    • Actions
    • Keyboard Events
    • Swipe Actions
    • DragNDrop
    • Orientation
    • Assertions
Powered by GitBook
On this page
  • DragNDrop using Elements on screen:
  • DragNDrop using XY-Coordinates of screen:

Was this helpful?

  1. Recipes

DragNDrop

DragNDrop using Elements on screen:

Create a reusable function using TouchAction class longPress` & moveTo method

helper.java
  public static void dragNDropByLongpress(WebElement element1, WebElement element2) {
        TouchAction dragNDrop = new TouchAction(driver).longPress(element1).moveTo(element2).release();
        dragNDrop.perform();
    }

To DragNDrop using Elements, import above function from helper.java class

test.java

$ helper.dragNDropByLongpress(sourceElement, destinationElement);

DragNDrop using XY-Coordinates of screen:

Create a reusable function using XY-Coordinates, TouchAction class longPress` & moveTo method

helper.java
  public static void dragNDropByCoordinatesTest(AndroidElement element1, AndroidElement element2) {
        Point center1 = element1.getCenter();
        Point center2 = element2.getCenter();

        TouchAction action = new TouchAction(driver).longPress(center1.x, center1.y).moveTo(center2.x, center2.y).release();
        action.perform();
    }

To DragNDrop using XY-Coordinates, import above function from helper.java class

test.java

$ helper.dragNDropByLongpress(sourceElement, destinationElement);
PreviousSwipe ActionsNextOrientation

Last updated 5 years ago

Was this helpful?