Issue with scrolling in AndroidDriver

Hi,

I am automating an android application. I want to scroll down in a list view to a tab and click it. Scrolling happening from top to bottom and bottom to top. But it can’t find the text on the screen. I have used below methods and none of them working for me.

driver.scrollTo(“text”).click();

Also
driver.scrollTo(“text”);
driver.findElement(By.xpath().click();

Also
driver.scrollToExact(“text”);

Please help me with code example. Thank you in advance.

do you have any logs? errors?

These are my appium logs

{“strategy”:“name”,“selector”:“Okay”,“context”:“”,“multiple”:false}}

info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding Okay using NAME with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=Okay, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[TEXT=Okay, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:{“ELEMENT”:“6”}}
info: [debug] Responding to client with success: {“status”:0,“value”:{“ELEMENT”:“6”},“sessionId”:“2dc198b5-1dd7-4fc3-9aec-ec1145074d77”}
info: ← POST /wd/hub/session/2dc198b5-1dd7-4fc3-9aec-ec1145074d77/element 200 6309.867 ms - 87 {“status”:0,“value”:{“ELEMENT”:“6”},“sessionId”:“2dc198b5-1dd7-4fc3-9aec-ec1145074d77”}
info: → POST /wd/hub/session/2dc198b5-1dd7-4fc3-9aec-ec1145074d77/element/6/click {“id”:“6”}
info: [debug] Pushing command to appium work queue: [“element:click”,{“elementId”:“6”}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“element:click”,“params”:{“elementId”:“6”}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:true}
info: [debug] Responding to client with success: {“status”:0,“value”:true,“sessionId”:“2dc198b5-1dd7-4fc3-9aec-ec1145074d77”}
info: ← POST /wd/hub/session/2dc198b5-1dd7-4fc3-9aec-ec1145074d77/element/6/click 200 453.767 ms - 76 {“status”:0,“value”:true,“sessionId”:“2dc198b5-1dd7-4fc3-9aec-ec1145074d77”}
info: → POST /wd/hub/session/2dc198b5-1dd7-4fc3-9aec-ec1145074d77/element {“using”:“-android uiautomator”,“value”:“new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().descriptionContains("Changing Minds").instance(0));new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("Changing Minds").instance(0));”}
info: [debug] Waiting up to 15000ms for condition
info: [debug] Pushing command to appium work queue: [“find”,{“strategy”:“-android uiautomator”,“selector”:“new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().descriptionContains("Changing Minds").instance(0));new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("Changing Minds").instance(0));”,“context”:“”,“multiple”:false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“-android uiautomator”,“selector”:“new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().descriptionContains("Changing Minds").instance(0));new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("Changing Minds").instance(0));”,“context”:“”,“multiple”:false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().descriptionContains(“Changing Minds”).instance(0));new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(“Changing Minds”).instance(0)); using ANDROID_UIAUTOMATOR with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Parsing scrollable: new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().descriptionContains(“Changing Minds”).instance(0))
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: boolean arg: true
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: int arg: 0
info: [debug] [BOOTSTRAP] [debug] UiScrollable invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException args: new UiSelector().descriptionContains(“Changing Minds”).instance(0),
info: [debug] [BOOTSTRAP] [debug] UiScrollable coerce type: class com.android.uiautomator.core.UiObject arg: new UiSelector().descriptionContains(“Changing Minds”).instance(0)
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: “Changing Minds”
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: int arg: 0
info: [debug] [BOOTSTRAP] [debug] Method name: scrollIntoView
info: [debug] [BOOTSTRAP] [debug] Setting uiObject for scrollIntoView
info: [debug] [BOOTSTRAP] [debug] Invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException with: com.android.uiautomator.core.UiObject@361cd4a2
info: [debug] [BOOTSTRAP] [debug] Invoke complete.
info: [debug] [BOOTSTRAP] [debug] Parsing scrollable: new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(“Changing Minds”).instance(0))
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: boolean arg: true
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: int arg: 0
info: [debug] [BOOTSTRAP] [debug] UiScrollable invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException args: new UiSelector().textContains(“Changing Minds”).instance(0),
info: [debug] [BOOTSTRAP] [debug] UiScrollable coerce type: class com.android.uiautomator.core.UiObject arg: new UiSelector().textContains(“Changing Minds”).instance(0)
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: “Changing Minds”
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: int arg: 0
info: [debug] [BOOTSTRAP] [debug] Method name: scrollIntoView
info: [debug] [BOOTSTRAP] [debug] Setting uiObject for scrollIntoView
info: [debug] [BOOTSTRAP] [debug] Invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException with: com.android.uiautomator.core.UiObject@2a5c1533
info: [debug] Didn’t get a new command in 60 secs, shutting down…
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: E:\SDK\platform-tools\adb.exe -s emulator-5554 shell “input keyevent 3”
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
warn: Trying to run a command when one is already in progress. Will spin a bit and try again
info: [debug] Sent shutdown command, waiting for UiAutomator to stop…
info: [debug] [BOOTSTRAP] [debug] Ignoring UiObjectNotFoundException when using reflection to invoke method.
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CONTAINS_DESCRIPTION=Changing Minds, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CONTAINS_TEXT=Changing Minds, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
info: [debug] [BOOTSTRAP] [debug] Finding new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().descriptionContains(“Changing Minds”).instance(0));new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(“Changing Minds”).instance(0)); using ANDROID_UIAUTOMATOR with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Parsing scrollable: new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().descriptionContains(“Changing Minds”).instance(0))
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: boolean arg: true
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: int arg: 0
info: [debug] [BOOTSTRAP] [debug] UiScrollable invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException args: new UiSelector().descriptionContains(“Changing Minds”).instance(0),
info: [debug] [BOOTSTRAP] [debug] UiScrollable coerce type: class com.android.uiautomator.core.UiObject arg: new UiSelector().descriptionContains(“Changing Minds”).instance(0)
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: “Changing Minds”
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: int arg: 0
info: [debug] [BOOTSTRAP] [debug] Method name: scrollIntoView
info: [debug] [BOOTSTRAP] [debug] Setting uiObject for scrollIntoView
info: [debug] [BOOTSTRAP] [debug] Not scrolling because scrollable does not exist: UiSelector[INSTANCE=0, SCROLLABLE=true]
info: [debug] [BOOTSTRAP] [debug] Parsing scrollable: new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(“Changing Minds”).instance(0))
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: boolean arg: true
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: int arg: 0
info: [debug] [BOOTSTRAP] [debug] UiScrollable invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException args: new UiSelector().textContains(“Changing Minds”).instance(0),
info: [debug] [BOOTSTRAP] [debug] UiScrollable coerce type: class com.android.uiautomator.core.UiObject arg: new UiSelector().textContains(“Changing Minds”).instance(0)
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: “Changing Minds”
info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: int arg: 0
info: [debug] [BOOTSTRAP] [debug] Method name: scrollIntoView
info: [debug] [BOOTSTRAP] [debug] Setting uiObject for scrollIntoView
info: [debug] [BOOTSTRAP] [debug] Not scrolling because scrollable does not exist: UiSelector[INSTANCE=0, SCROLLABLE=true]
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CONTAINS_DESCRIPTION=Changing Minds, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CONTAINS_TEXT=Changing Minds, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:7,“value”:“No element found”}
info: [debug] Condition unmet after 76198ms. 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”:“No element found”},“sessionId”:null}
info: ← POST /wd/hub/session/2dc198b5-1dd7-4fc3-9aec-ec1145074d77/element 500 76200.367 ms - 161
info: → DELETE /wd/hub/session/2dc198b5-1dd7-4fc3-9aec-ec1145074d77 {}
info: ← DELETE /wd/hub/session/2dc198b5-1dd7-4fc3-9aec-ec1145074d77 404 1.683 ms - 40
warn: UiAutomator did not shut down fast enough, calling it gone
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] We shut down because no new commands came in

on the logs that you provided there is an error of:
“An element could not be located on the page using the given search parameters.”
are you sure the element “text” exists on the page?

Hi,

This is how the text display in UI automator viewer.

try to write “Changing Minds” instead of “text”

I have written “Changing Minds” instead of “text” in the code.

Yes.I have written “Changing Minds” instead of “text” in the code.

use better:

new TouchAction((MobileDriver) driver).tap(driver.findElement(MobileBy.id("your_element_resource_id"))).perform();

or

driver.findElement(MobileBy.id("your_element_resource_id")).click();
1 Like

is this a text field or an element that you can press on?
have you tried to press on the element using appium inspector?

Yes, This is a element when tap on directed to another screen.

Try this one:
driver.scrollToExact(“text”)
then
driver.findElementByName(“Changing Minds”).click()

don’t use scrollToExact & click together.

1 Like

Hi,

I tried. But didn’t work.

Try using the Index once… If all the indexes in the view are not same.

hi, have you solved the problem? i met the same problems ,and i have no idea

scrollTo and scrollToExact methods are not stable and due to this reason those have been deprecated and removed in java client 4. There is not an exact alternative for these methods, instead you should change your scrolling case to swiping.

appiumDriver.swipe(int countForSwipeDown, int startx, int starty, int endx, int endy, int duration)

If you insist to use the old way, there is a workaround explained here: Java-client 4.0.0 released

countForSwipeDown

what it does ? please more ellaborate?

It means count for swipe down :slight_smile: You should enter the number of the swipe down move. You should give the coordinates from visible screen by the way. Those are the ones the move will start end the ones that move will end.

1 Like

Hi Taylan

I am using Java client 4.1.1. In this I am not getting first argument means ‘count for swipe down’

driver.swipe(startx, starty, endx, endy, time_in_ms);

This is the full syntax.

Sorry harsh, I forgot to write to whole code.

Swipe is an action method within the visible area of the page. If you need to scroll to an element but a 1 swipe action is not enough to get there, you need to do the action more than once. So, you can loop the swipe method with a count parameter:

public void swipe(int countForSwipeDown, int startx, int starty, int endx, int endy, int duration) {
    for (int i = 0; i < countForSwipeDown; i++) {
        androidDriver.swipe(startx, starty, endx, endy, duration);
    }
}

Of course best practice is automate the count, you need to swipe until see the element.
Sorry for forgoting to explain. I hope this helps…