Anyone else facing issues with scrollTo?

Tried a simple appium test.

driver.scrollTo(“HockeyApp”);

gives the following error. It says that the element is not found.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:269)
    at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:27)
    at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
    at io.appium.java_client.ios.IOSElement.execute(IOSElement.java:1)
    at org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:172)
    at io.appium.java_client.ios.IOSElement.findElementByIosUIAutomation(IOSElement.java:20)
    at io.appium.java_client.ios.IOSElement.scrollTo(IOSElement.java:39)
    at io.appium.java_client.ios.IOSElement.scrollTo(IOSElement.java:1)
    at io.appium.java_client.ios.IOSDriver.scrollTo(IOSDriver.java:50)
    at com.test.appium.Extra.IosDriverTest.test(IosDriverTest.java:92)

On the appium server side. This is the log for reference.

info: [debug] Pushing command to appium work queue: "au.getElementByUIAutomation('.scrollToElementWithPredicate(\\\"name CONTAINS \\'HockeyApp\\'\\\")', '22')"
info: [debug] Sending command to instruments: au.getElementByUIAutomation('.scrollToElementWithPredicate(\"name CONTAINS \'HockeyApp\'\")', '22')
info: [debug] [INST] 2015-07-27 06:12:49 +0000 Debug: Got new command 54 from instruments: au.getElementByUIAutomation('.scrollToElementWithPredicate(\"name CONTAINS \'HockeyApp\'\")', '22')
info: [debug] [INST] 2015-07-27 06:12:49 +0000 Debug: evaluating au.getElementByUIAutomation('.scrollToElementWithPredicate(\"name CONTAINS \'HockeyApp\'\")', '22')
info: [debug] [INST] 2015-07-27 06:12:49 +0000 Debug: byUIAutomation: evaluating code: $.getElement('22').scrollToElementWithPredicate("name CONTAINS 'HockeyApp'")
info: [debug] [INST] 2015-07-27 06:12:49 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-07-27 06:12:49 +0000 Debug: responding with:
info: [debug] [INST] 2015-07-27 06:12:49 +0000 Debug: Running system command #55: /usr/local/bin/node /Users/nakeer/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Waited for 721ms so far
info: [debug] Pushing command to appium work queue: "au.getElementByUIAutomation('.scrollToElementWithPredicate(\\\"name CONTAINS \\'HockeyApp\\'\\\")', '22')"
info: [debug] Sending command to instruments: au.getElementByUIAutomation('.scrollToElementWithPredicate(\"name CONTAINS \'HockeyApp\'\")', '22')
info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Condition unmet after 1303ms. Timing out.
info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":""},"sessionId":"3c9a766d-8b7a-48da-8b14-d98d7c6addd0"}

You will need to find the element first and then scroll to it. You can use the different ways to identify an element within an app.

For reference you can go here: http://appium.io/slate/en/master/?java#java-example

I think we have a Catch22 here - at least for how I’ve seen Appium work on Android & iOS.
For elements that below the bottom of the screen the various find commands do not work.
I’ve had to create a wrapper that tries multiple times to find an element. In the loop if the find fails then it scrolls down (or up) and tries the find again.

I would love for scrollTo to really work - i.e. actively scroll down (on its own) the entire page until it finds the element.

Hi @curtissiemens: can you help with the wrapper,

With java client 3.2.1, I have manged to make the scroll work for android.
But there are couple of issues with scrollTo for android. Even if the element is present on the screen. It still goes up and down once and then comes back and then finds the element.

Meanwhile its not working on iOS. Not sure why. So used the workaround which most of them suggested.

public void scrollToForAndroid(String element) {
    getAppiumWebDriver().scrollTo(element);
}

public void scrollToForIos(String locator) {
    HashMap<String, String> scrollObject = new HashMap<String, String>();
    RemoteWebElement webElement = (RemoteWebElement)((IOSDriver) getAppiumWebDriver()).findElementByName(locator);
    JavascriptExecutor js = (JavascriptExecutor) getAppiumWebDriver();
    String webElementId = ((RemoteWebElement) webElement).getId();
    scrollObject.put("text", locator);
    scrollObject.put("element", webElementId);
    js.executeScript("mobile: scrollTo", scrollObject);
}

I think scrollTo does scroll up or down on its own the entire page to find the elements isn’t it? But you can only locate with text or content description, I wish scrollTo supports more searching methods.

Looks like that the request from many!!
may be with next release.