Skip to content Skip to sidebar Skip to footer

Vertical Scrolling In Android App Using Appium-python

Following is the UI for android app. In this a UI of Friends list is visible. It have total number of 26 friends. I want to scroll the UI and want to see all the friends. I want

Solution 1:

I had same problem. Most of the suggested solutions didn't work. Anyways, I found a solution you can see below:

# import touch eventsfrom appium.webdriver.common.touch_action import TouchAction

    # Find the list element. list = driver.find_element_by_id('com.abc.android.abc:id/common_tab_list')
    # define touch
    action = TouchAction(driver)

    # adjust here to your needs !for x inrange(0,10):
       action.press(x=750,y=1750).move_to(x=0, y=-75).perform()

the main part is the for loop. Basically its scrolling vertically 10 times. You may need to give different x and y coordinates. You can easily find this out when you enable "pointer location" on your device. This will show x and y coordinates when you touch your screen. To enable it simply go to

  1. settings
  2. developer options
  3. pointer location (names may differ I have german language on my phone)

Then touch on the bottom of your device and on top you will see the coordinates. This you can add to "action.press(x=yourX, y=yourY)...."

move_to() - since you want vertical scroll leave x as it is. y has a negative. Negative means that we are actually scrolling up not down.

perfrom() is perform. Not much to say.

Now I want to add 1 more thing. Instead of a for loop you can do the following:

 action.press(x=750,y=1750).move_to(x=0, y=-200).release().perform()

Noticed the difference? It's release(). When you add this I found that the list will be scrolled smoothly. Like when you swipe up and the list has some inertia.

Im not an expert but my answer should help you at least. Good luck

Solution 2:

The scrollable area should be tagged as "scrollable". You can use Android UIAutomator and UiScrollable to solve this.

user_scroll = 'newUiScrollable(new UiSelector().scrollable(true).' +
     'instance(0)).scrollIntoView(new UiSelector().text("user-text").instance(0))'
user = self.driver.find_element_by_android_uiautomator(user_scroll)

What we're doing is selecting the scrolling area that we care about. Using that, we scroll to a specific element. In this case, we're scrolling to an element that contains some specific text.

If you want to scroll to each of the users one at a time, then it should be easy to iterate through using a different instance each time for UiSelector ".text". If you just want to scroll to the bottom user, you can just search for the user that's there.

Solution 3:

The only way I got it working using the TouchAction is:

ta = TouchAction(driver)
ta.tap(x=100, y=200).wait(100).move_to(x=100, y=80).wait(100).release()
ta.perform()

Without those waits the Iphone goes crazy.

Post a Comment for "Vertical Scrolling In Android App Using Appium-python"