Driver swipe not precise

So i work on a native application with Android 4.4+
I use the java client 1.5.
I have an activity with :
-spinner, some button and then a RecycleView.

I want to scroll in the recycleview. Each row have a specific height wich i can compute. So to scroll one row i do this : ( this is pseudocode )
I compute each coordinate. With rowElement.getLocation().getX()
And
rowElement.getSize().getHeight() …

driver.swipe(centerOfRowX, bottomRowY, centerOfRowX,topRowY,duration) ;

It should scroll for all the height of the row. But it doesnt scroll entirely. Why ?
( i got the same size and position from the uiautomationviewer and the code )

Hi @jbeat ,
Maybe You can use scroll to element ?

public MobileElement scroll_to(String value) { return driver.scrollTo(value); }

Hi, well the problem is that since i have a spinner and a recycle view.
When i use scrollTo it target the spinner. And it doesnt scroll the
recycleview. ( the spinner is before the recycleview ) is there a way to
specify wich list to target ?

scrollTo is deprecated in 1.5

Prior to 1.5, you can specify which element to scroll by adding an element node to the scrollObject.

see example here:

// java
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put(“direction”, “down”);
scrollObject.put(“element”, ((RemoteWebElement) element).getId());
js.executeScript(“mobile: scroll”, scrollObject);

I think this might be the internal “slop” property built into the Android system. Scrolling in Android was designed so that if the user moves their finger a tiny bit on the screen while tapping, the system will still recognize it as a “tap”. This is necessary because when a human finger taps on the Android screen, rarely will the tap position remain precisely on a particular position on the screen. Slop, then, defines the cutoff point between when a touch+move will count as a tap and when the touch+move will count as swiping (or scrolling in WebDriver terminology).

The slop value is actually quite sizable (somewhere on the order of 10% of 1 inch). It can be queried using the Android ViewConfiguration class. However, I do not think Appium currently provides a way to query this class for information (Feel free to correct me here if I’m wrong, though! Would be an interesting feature to request if this feature isn’t already implemented).

Thanks ! It work perfectly i just code in Android studio :

ViewConfiguration config = new ViewConfiguration();
System.out.println("Touch SLOP : " + config.getScaledTouchSlop());

for my device, add it to the number of pixel in my swipe, and its good !

1 Like

When I was implementing screenshot comparison I have encountered the same problem - scroll was completely inconsistent.
After trying different approaches I have finally found the one that works.
I used pressKeyCode() method with KEYCODE_DPAD_DOWN/KEYCODE_DPAD_UP as a parameter to navigate back and forth.
However, there is a catch - the View you want to navigate to has to be focusable (you can set android:focusable=true in XML layout).