How to perform Drag and Drop operation in android device using appium? – pCloudy – Question and Answers
Home >> Appium Tricks and Tricks >> How to perform Drag and Drop operation ...

How to perform Drag and Drop operation in android device using appium?


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;

Leave a Reply

Your email address will not be published. Required fields are marked *