scrollTo does not work in android using selenium webdriver java

1,791 views
Skip to first unread message

Supriya Vivek

unread,
Aug 27, 2014, 2:05:02 AM8/27/14
to appium-...@googlegroups.com
I have to fetch the number of elements in the list and print the same, there are more than 10 elements so i need to scroll and take the count. here is my code to scroll

List<WebElement> progList = driver.findElements(By.id("com.mitv:id/tvguide_program_line_live"));
        count=progList.size();
       
        String lastlink="Agrega canales a tu programación";       
        WebElement scrollTodos = driver.findElement(By.id("com.mitv:id/tvguide_table_listview"));
        scrollDown(scrollTodos, lastlink);
       
        count=count+progList.size();
        System.out.println(count);   

public void scrollDown(WebElement scrollTodos, String lastlink) throws InterruptedException {
        implicitWait(driver, 1, TimeUnit.MINUTES);
        JavascriptExecutor js = (JavascriptExecutor) driver;
        HashMap<String, String> scrollObject = new HashMap<String, String>();
//        scrollObject.put("direction", "down");
        scrollObject.put("text", lastlink);
        scrollObject.put("element",( (RemoteWebElement) scrollTodos).getId());
        js.executeScript("mobile: scrollTo", scrollObject);
    }

The scroll option scrolls down a little and gives me an error. can anyone please guide me how to scroll and get the count of elements in the list.
here is the error i am getting.

App launched
FAILED: androidTest
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4.89 seconds
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: host: '*********', ip: '*********', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.8.0_05'
Driver info: io.appium.java_client.AppiumDriver
Capabilities [{networkConnectionEnabled=true, desired={}, platformVersion=4.1, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, platform=LINUX}]
Session ID: c815e3c0-e197-4a3a-86e1-e2b8d6c97ece
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    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:599)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:95)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:508)
    at se.test.MiTvAppTest.AndroidApp.scrollDown(AndroidApp.java:107)
    at se.test.MiTvAppTest.AndroidApp.testNoOfChannels(AndroidApp.java:83)
    at se.test.MiTvAppTest.AndroidApp.androidTest(AndroidApp.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

Screen Shot 2014-08-27 at 1.03.37 AM.png

Isaac Murchie

unread,
Aug 27, 2014, 12:20:47 PM8/27/14
to Supriya Vivek, appium-...@googlegroups.com
What is the error in the Appium server logs? That would be more useful.

You could also scroll using the UI Automator commands, as discussed here: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/uiautomator_uiselector.md


--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

Supriya Vivek

unread,
Sep 1, 2014, 12:46:48 AM9/1/14
to appium-...@googlegroups.com, supriy...@gmail.com
Hi Isaac

I am able to scroll by using the same code i had posted before but the only change i made is to quit after testing the scroll functionality.
using driver.quit(). but the problem is I have a list of elements and i want to count the elements.
before scrolling i am getting the count as 5 which is on the screen and after scrolling i am getting the count as 5 but the remaining 2 values in between the process of scrolling is not counted. Can anyone help me to find the no. of elements in the listview?

Thanks In Advance.

Supriya Vivek

unread,
Sep 1, 2014, 12:47:16 AM9/1/14
to appium-...@googlegroups.com, supriy...@gmail.com
I am using selenium webdriver with java

Supriya Vivek

unread,
Sep 1, 2014, 6:37:59 AM9/1/14
to appium-...@googlegroups.com, supriy...@gmail.com
This is my appium log I am still facing this issue, some times it works and some times its not.


info: <-- POST /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/elements 200 347.621 ms - 157 {"status":0,"value":[{"ELEMENT":"9"},{"ELEMENT":"10"},{"ELEMENT":"11"},{"ELEMENT":"12"},{"ELEMENT":"13"}],"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}

debug: Responding to client with success: {"status":0,"value":[{"ELEMENT":"9"},{"ELEMENT":"10"},{"ELEMENT":"11"},{"ELEMENT":"12"},{"ELEMENT":"13"}],"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}
debug: Appium request initiated at /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/element
debug: Request received with params: {"using":"id","value":"com.mitv:id/tvguide_table_listview"}
debug: Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.mitv:id/tvguide_table_listview","context":"","multiple":false}]
debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.mitv:id/tvguide_table_listview","context":"","multiple":false}}
debug: [BOOTSTRAP] [debug] Got command of type ACTION
debug: [BOOTSTRAP] [debug] Got command action: find
debug: [BOOTSTRAP] [debug] Finding com.mitv:id/tvguide_table_listview using ID with the contextId:  multiple: false
debug: [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.mitv:id/tvguide_table_listview]

info: --> POST /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/element {"using":"id","value":"com.mitv:id/tvguide_table_listview"}

debug: Responding to client with success: {"status":0,"value":{"ELEMENT":"14"},"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}

info: <-- POST /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/element 200 36.900 ms - 88 {"status":0,"value":{"ELEMENT":"14"},"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}

debug: [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"14"},"status":0}

info: --> POST /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/timeouts/implicit_wait {"ms":60000}

debug: Appium request initiated at /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/timeouts/implicit_wait
debug: Request received with params: {"ms":60000}
debug: Set Android implicit wait to 60000ms
debug: Responding to client with success: {"status":0,"value":null,"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}
debug: Appium request initiated at /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/execute
debug: Request received with params: {"args":[{"text":"Agrega canales a tu programación","direction":"down","element":"14"}],"script":"mobile: scrollTo"}
debug: Pushing command to appium work queue: ["element:scrollTo",{"text":"Agrega canales a tu programación","direction":"down","elementId":"14"}]
debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:scrollTo","params":{"text":"Agrega canales a tu programación","direction":"down","elementId":"14"}}
debug: [BOOTSTRAP] [debug] Got command of type ACTION
debug: [BOOTSTRAP] [debug] Got command action: scrollTo

info: <-- POST /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/timeouts/implicit_wait 200 1.361 ms - 76 {"status":0,"value":null,"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}
info: --> POST /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/execute {"args":[{"text":"Agrega canales a tu programación","direction":"down","element":"14"}],"script":"mobile: scrollTo"}
warn: scrollTo will be removed in a future version of appium

debug: Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"Could not scroll element into view: Agrega canales a tu programación"},"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}

info: <-- POST /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff/execute 500 5789.939 ms - 238

debug: [BOOTSTRAP] [debug] Returning result: {"value":"Could not scroll element into view: Agrega canales a tu programación","status":13}

info: --> DELETE /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff {}

debug: Appium request initiated at /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff

info: Shutting down appium session

debug: Request received with params: {}
debug: Pressing the HOME button
debug: executing: "/Users/indpro/Downloads/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb" -s 192.168.56.101:5555 shell "input keyevent 3"

debug: Stopping logcat capture

debug: Logcat terminated with code null, signal SIGTERM

debug: Sent shutdown command, waiting for UiAutomator to stop...
debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
debug: [BOOTSTRAP] [debug] Got command of type SHUTDOWN
debug: [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
debug: [BOOTSTRAP] [debug] Closed client connection
debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
debug: [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
debug: [UIAUTOMATOR STDOUT] Time: 32.638
debug: [UIAUTOMATOR STDOUT] OK (1 test)

debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1

debug: UiAutomator shut down normally

debug: Cleaning up android objects
debug: Cleaning up appium session
debug: Responding to client with success: {"status":0,"value":null,"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}

info: <-- DELETE /wd/hub/session/2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff 200 5448.854 ms - 76 {"status":0,"value":null,"sessionId":"2fb5ab0f-f2ac-49b4-bf37-ac15cc4121ff"}

info: --> GET /wd/hub/status {}

debug: Appium request initiated at /wd/hub/status

info: <-- GET /wd/hub/status 200 2.200 ms - 104 {"status":0,"value":{"build":{"version":"1.2.0","revision":"e53f49c706a25242e66d36685c268b599cc18da5"}}}

debug: Request received with params: {}
debug: Responding to client with success: {"status":0,"value":{"build":{"version":"1.2.0","revision":"e53f49c706a25242e66d36685c268b599cc18da5"}}}

debug: Appium request initiated at /wd/hub/status

Rejish R

unread,
Sep 3, 2014, 7:59:09 AM9/3/14
to appium-...@googlegroups.com, supriy...@gmail.com
Hi Supriya Vivek,

Were you able to solve the above issues. if so kindly let me know how to fix this

Regards,
Rejish
Reply all
Reply to author
Forward
0 new messages