scrollTo (Android): MalformedJsonException

Hi,
I have some problems with scrollTo method from Java Client…

Appium Server 1.2.2.
Java Client 1.6

driver = new AppiumDriver(new URL(“http://127.0.0.1:4723/wd/hub”), cap);
driver.scrollTo(“vTF Cafe”);

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 7
at com.google.gson.JsonParser.parse(JsonParser.java:65)
at com.google.gson.JsonParser.parse(JsonParser.java:45)
at io.appium.java_client.ComplexFind.execute(ComplexFind.java:81)
at io.appium.java_client.ComplexFind.scrollTo(ComplexFind.java:55)
at io.appium.java_client.AppiumDriver.scrollTo(AppiumDriver.java:524)
at hello.bestellbarTest.main(bestellbarTest.java:39)
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 7
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:531)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:414)
at com.google.gson.JsonParser.parse(JsonParser.java:60)
… 5 more

info: [debug] Device launched! Ready for commands
info: [debug] Setting command timeout to the default of 60 secs
info: [debug] Appium session started with sessionId 8482a842-1a25-49d8-b576-7a92
0f82a47a
info: <-- POST /wd/hub/session 303 11981.774 ms - 9
info: --> GET /wd/hub/session/8482a842-1a25-49d8-b576-7a920f82a47a {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“platform”
:“LINUX”,“browserName”:“Android”,“platformVersion”:“4.4.2”,“webStorageEnabled”:f
alse,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“ne
tworkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desir
ed”:{“platformVersion”:“4.4.2”,“app”:“D:\Entwicklung\Workspace\eclipse\Testa
utomatisierung\src\main\resources\examples\testscripts\bestellbar_mobile\
bestellbar_testumgebung.apk”,“platformName”:“Android”,“deviceName”:“android”,“ap
pActivity”:".GarconActivity",“appWaitActivity”:".CheckInActivity",“udid”:“FA41WW
910329”,“appPackage”:“de.viadee.garcon.android”},“app”:“D:\Entwicklung\Workspa
ce\eclipse\Testautomatisierung\src\main\resources\examples\testscripts\b
estellbar_mobile\bestellbar_testumgebung.apk”,“platformName”:“Android”,“deviceN
ame”:“android”,“appActivity”:".GarconActivity",“appWaitActivity”:".CheckInActivi
ty",“udid”:“FA41WW910329”,“appPackage”:“de.viadee.garcon.android”},“sessionId”:"
8482a842-1a25-49d8-b576-7a920f82a47a"}
info: <-- GET /wd/hub/session/8482a842-1a25-49d8-b576-7a920f82a47a 200 16.203 ms

  • 1029 {“status”:0,“value”:{“platform”:“LINUX”,“browserName”:“Android”,“platfor
    mVersion”:“4.4.2”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEn
    abled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationCon
    textEnabled”:false,“warnings”:{},“desired”:{“platformVersion”:“4.4.2”,“app”:“D:
    \Entwicklung\Workspace\eclipse\Testautomatisierung\src\main\resources\exa
    mples\testscripts\bestellbar_mobile\bestellbar_testumgebung.apk”,“platformNam
    e”:“Android”,“deviceName”:“android”,“appActivity”:".GarconActivity",“appWaitActi
    vity”:".CheckInActivity",“udid”:“FA41WW910329”,“appPackage”:“de.viadee.garcon.an
    droid”},“app”:“D:\Entwicklung\Workspace\eclipse\Testautomatisierung\src\ma
    in\resources\examples\testscripts\bestellbar_mobile\bestellbar_testumgebung
    .apk”,“platformName”:“Android”,“deviceName”:“android”,“appActivity”:".GarconActi
    vity",“appWaitActivity”:".CheckInActivity",“udid”:“FA41WW910329”,“appPackage”:“d
    e.viadee.garcon.android”},“sessionId”:“8482a842-1a25-49d8-b576-7a920f82a47a”}
    info: --> POST /wd/hub/session/8482a842-1a25-49d8-b576-7a920f82a47a/appium/app/c
    omplex_find [“scroll”,[[3,“vTF Cafe”]],[[7,“vTF Cafe”]]]
    info: [debug] Responding to client that we did not find a valid resource
    info: <-- POST /wd/hub/session/8482a842-1a25-49d8-b576-7a920f82a47a/appium/app/c
    omplex_find 404 13.127 ms - 47
    info: --> DELETE /wd/hub/session/8482a842-1a25-49d8-b576-7a920f82a47a {}
    info: Shutting down appium session
    info: [debug] Pressing the HOME button

I know that complexFind is deprecated? but i need to scroll to an element.
Could someone help me?

Thanks

scrollTo will be fixed in the Java bindings soon. There’s an open issue.

2 Likes

I’m too waiting for this fix, also is there any addition is going to come for scrollTo a element [by id/xpath] for the dynamic content [since no permanent text is available] !

Well i agree with @p00j4 scroll to an element by say (findElementByAccessibilityId)/xpath would be the best way.

I think that is fix with new java client. Kindly upate your pom.xml and add java client dependencied.

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>2.0.0</version>
</dependency>

Hello, I didn’t want to create a new thread since this seems very similar to the issue im having.

I am trying to scroll on Android physical device using this method ( in Ruby ):

execute_script “mobile: scrollTo”, :element => find_element(:name, “ELEMENT NAME”).ref

I’ve also tried scrolling using just coordinates AND swiping - still nothing.

Wanted to see if anyone could give me any advice on how to do this better? Or if anyone else is having any issues with scrolling on Android?

I have modified below method for java and it works

public WebElement scrollTo(String text) {
    String uiScrollables = "new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+text+"\").instance(0))";
    return driver.findElementByAndroidUIAutomator(uiScrollables);
  }