Drag And Drop Action
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;
public class Example6DragAndDropAction {
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities dc= new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\more\\com.mobeta.android.demodslv-0.5.0-3_APKdot.com.apk");
URL url =new URL("http://127.0.0.1:4723/wd/hub");
AndroidDriver
//Navigation
driver.findElementByXPath("/hierarchy/android.widget.FrameLayout/android.view.View /android.widget.FrameLayout[2]/android.widget.ListView/android.widget.LinearLayout[1] /android.widget.TextView[1]").click();
//Chick Corea
WebElement source=driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(2);
WebElement target=driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(5);
TouchAction action=new TouchAction((MobileDriver)driver);
//drag and drop
action.longPress(ElementOption.element(source)).moveTo(ElementOption.element(target)).release().perform();
System.out.println("Element has been droped at destination successfully.");
}
}