How to perform Drag and Drop operation in android device using appium?
Posted on April 3, 2019
By Shibu Panda
Code Snippet:
//Java-Client version: Latest(7.0.0)
//Appium version: 1.9.1
driver.findElement(By.xpath("//android.widget.TextView[@resource-id='com.mobeta.android.demodslv:id/activity_desc']")).click();
MobileElement dragElement = (MobileElement) driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(2);
MobileElement dropElement = (MobileElement) driver.findElementsById("com.mobeta.android.demodslv:id/drag_handle").get(5);
//Created object of TouchAction class.
AndroidTouchAction finger1= new AndroidTouchAction(driver);
int xCoordinate = dragElement.getLocation().getX();
int yCoordinate = dropElement.getLocation().getY();
finger1.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(dragElement))).moveTo(PointOption.point(xCoordinate,yCoordinate)).release().perform();
int xOffset=imageElement.getLocation().getX()+imageElement.getSize().getWidth()/2;
int yOffset= imageElement.getLocation().getY()+imageElement.getSize().getHeight()/2;