ScrollTo and ScrollToExact function is not working

Hi,
am using the latest version of appium(1.3.4.1) and i have more than 10 options in the list.am trying to launch 10th option from the list bu using ScrollTo("About App) /ScrollToExact(“About App”) and its scrolling up but not below.Loop is keep on continuing untill i stop…

and also used driver.swipe(600, 700, 600, 200, 2) and launches other option from the list rather than scrolling.

using appium 1.2 ,wrote a swipe function as below and works fine but in 1.3.4.1 this is not working.(Quitting out of the application)
/public void swiping(Double startX,Double startY,Double endX,Double endY,Double duration)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new HashMap<String, Double>();
// swipeObject.put(“touchCount”, 1.0);
swipeObject.put(“startX”, startX);
swipeObject.put(“startY”, startY);
swipeObject.put(“endX”, endX);
swipeObject.put(“endY”, endY);
swipeObject.put(“duration”, duration);
js.executeScript(“mobile: swipe”, swipeObject);
}
/

Please help me ASAP

@mohanms

I wrote about this same problem recently along with a potential solution:

Hi ,

I have same problem in “ScrollTo” and “ScrollToExact” methods. I am new to Appium , I couldn’t get provided workaround.

In my case I need to scroll until “Home” text , can you put Workaround code for the same.

I am using - AppiumForWindows-1.3.4.1 version and java-client-2.1.0.

Regards,
Kiran

I looked at the Java implementation of scrollTo and found this change:
https://github.com/appium/java-client/commit/88197f71a146e69ce4e6696cad3d24f190d89a36

The code that used to be implemented in the Android tree is below:

public MobileElement scrollTo(String text) {
    String uiScrollables = AndroidDriver.UiScrollable("new UiSelector().descriptionContains(\"" + text + "\")") +
	AndroidDriver.UiScrollable("new UiSelector().textContains(\"" + text + "\")");
    return (MobileElement) findElementByAndroidUIAutomator(uiScrollables);
}

I’m not a Java expert, but this code should work until this problem is fixed. This assumes you are searching only by text and not by description.

public MobileElement scrollTo(String text) {
    String uiScrollables = AndroidDriver.UiScrollable("new UiSelector().textContains(\"" + text + "\")");
    return (MobileElement) findElementByAndroidUIAutomator(uiScrollables);
}

Any suggestion for an iOS fix (assuming this only works for Android based upon method names)? Can’t get any scrolling working, either by swipe or scrollTo/Exact in iOS.

It’s very similar code. Here’s what’s implemented for iOS at: https://github.com/appium/ruby_lib/blob/d4517b878763523068f99b89b38a1ea3b0a98c4b/lib/appium_lib/android/element/generic.rb

def scroll_to text
  text = %Q("#{text}")

  args = scroll_uiselector("new UiSelector().textContains(#{text})") +
         scroll_uiselector("new UiSelector().descriptionContains(#{text})")

  find_element :uiautomator, args
end

Change args to

  args = scroll_uiselector("new UiSelector().textContains(#{text})")

Or descriptionContains if that’s your preference

what library do we need to import for uiScrollable ? I’m new to appium

It’s uiautomator code. I believe it’s pulled in from appium_lib which you should already have.