Drag & Drop in HorizontalScrollView, moveTo() + waitAction() bug

  • Appium 1.3.6
  • Java-client 2.2.0
  • Android : tried on Nexus 5
  • Linux

Hello, I’m trying to perform a Drag & Drop but I need to scroll horizontally before dropping to the correct element (there are more elements than window width).

I saw there are wait methods() like waitAction() but it seems it doesn’t work with moveTo(). I need to set the duration of the moveTo() gesture because the scroll is linked to the speed of the gesture.

Currently the moveTo() is instantaneous even used with waitAction(10000). So it prevents me to scroll like I want.

Here what I’m trying to do :

TouchAction a1 = new TouchAction(getDriver());

int swipeOffset = 10;
boolean elementIsNotDisplayed = true;

//waitAction ignored for moveTo, the gesture is instantaneous, 
//it doesn't take 10sec to perform
a1.press(el_Drag).waitAction(2000).moveTo(1010, 1201).waitAction(10000).perform();

while (elementIsNotDisplayed) {
    try {
        MobileElement el = (MobileElement) driver.find(Drop element);
        elementIsNotDisplayed = false;
    } catch (NoSuchElementException e) {
        a1.moveTo(1010 + swipeOffset, 1201).waitAction(10000).perform();
    }
}

a1.moveTo(el_Drop).release().perform();

So basically I want to press on dragged element, moveTo specific location with a timed gesture, to perform my horizontalScrollView, and use other moveTo() to scroll to desired element if needed.
And then release the element at the correct location. Drag&Drop with scroll during it.

So please, what I am doing wrong? I just want to use moveTo() similarly to swipe(int duration).

From doc : “Appium performs the events in sequence. You can add a wait event to control
the timing of the gesture.”

Remove waitAction() methods in your statement. I see in forums that if you keep wait or waitAction, it is not working. If you omit it, it may work.

Try the following statement syntax:

AndroidDriver driver;
WebElement sourceElement=driver.findxxx  //your preferred method
WebElement targetElement=driver.findxxx  //your preferred method
TouchAction dragNDrop = new TouchAction(driver).longPress(sourceElement).moveTo(targetElement).release();
dragNDrop.perform();

Let us know if the above helped.

My problem is the targetElement isn’t present when I begin the drag and drop (Android). I have to keep the press and move until the border of the screen to launch the automatic horizontal scroll and when the correct element appears, then I want to drop (release).

It may be necessary for me to do multiple moveTo() just to get back() the correct targetElement and launch the scroll multiple times.

So I think it could be useful to overload moveTo() with int duration parameter as swipe() method.

My question is more if moveTo method’s dragging speed could be changed (and we would be able to see the drag&drop slowly if needed. Currently I just see my sourceElement at one location and then instantaneously at another location, no matter what I use).

It seems we can’t use longPress this way :

a1.longPress(sourceElement).moveTo(1010, 1201).perform();
a1.moveTo(1014, 1201).perform();
a1.moveTo(targetElement).release().perform();

With just press() I keep the element active.

I have to check element presence between each moveTo.

Edit : I just looked at swipe method, it’s touchAction.press(startx, starty).waitAction(duration), so it seems we just can’t apply the waitAction to moveTo. Woult it be possible to do that in appium?

Well, interesting, if I specify the drag&drop as you said UD, with targetElement present, it works fine, and even if the drag&drop is fast, it’s not instantaneous.

But if I specify the location of each element (approximately, I don’t calculate the center), it doesn’t work.

It works :

a1.longPress(sourceEl).moveTo(targetEl).release().perform();

It doesn’t work :

a1.longPress(207,1223).moveTo(1006,1223).release().perform();

This way there is still no solution to Drag&Drop when targetElement is not present on screen.

Hi Fanch for Horizontal scroll the targetElement initially not appears on screen,its visible only on scroll to end.
How to make sure target element visible or is there any approach.

For me you can’t for drag & drop

@Fanch can you just let me know what is code for horizontal scroll.
image is attached and bottom menu is scrollable.
in starting some function do not show so i just want to scroll and find out them left to right order.

im using java 8 and latest appium.