0

I create tests using Appium+Python to test IOs app. I want to scroll the page. Here is the code

    def scroll_page(self):
       action = TouchAction(self)
       action.press(BrowsePageElements.firs_element_to_scroll(self)).
              move_to(BrowsePageElements.second_element_to_scroll(self)).perform()

When I'm trying to run this function, I get an error

error screenshot

Could you help me to find out, how to fix this error?

3 Answers3

1

Appium Python has a native scroll function. It works for both Android and iOS.

driver.scroll(origin_el, destination_el, duration=None), where duration is an optional argument. This function scrolls origin_el to the location of destination_el.

Link to scroll source code

The Appium documentation is rather spotty and needs updating. However, the source code is documented well enough to understand and learn the program.

Surilan
  • 93
  • 1
  • 11
1

This currently works for me:

    ...
    SCROLL_DUR_MS = 3000
    ...
    window_size = self.driver.get_window_size()
    self.scroll_y_top = window_size['height'] * 0.2
    self.scroll_y_bottom = window_size['height'] * 0.8
    self.scroll_x = window_size['width'] * 0.5
    ...

def scroll_up(self):
    self._y_scroll(self.scroll_y_top, self.scroll_y_bottom)

def scroll_down(self):
    self._y_scroll(self.scroll_y_bottom, self.scroll_y_top)

def _y_scroll(self, y_start, y_end):
    actions = TouchAction(self.driver)
    actions.long_press(None, self.scroll_x, y_start, SCROLL_DUR_MS)
    actions.move_to(None, self.scroll_x, y_end)
    actions.perform()

It scrolls slowly over 3s because I want it to be controlled, but you could shorten SCROLL_DUR_MS (the duration of the scroll action in milliseconds) if you want something more zoomy. I also went away from using elements as the start and/or end points because I wanted something general that would work with any screen content.

For scroll_y_top and scroll_y_bottom I picked 20% in from the top and bottom of the screen just to make sure I wasn't hitting anything at the borders (like the navigation bar at the top of iOS Preferences or an info bar at the bottom of the app I was working in). I also ran into a "bug" where it wasn't scrolling when I left scroll_x as 0, but it turns out that it wasn't registering the left edge as inside the scrolling area for the app I was working in.

Hope this helps.

0

In the past when i've run into issues scrolling for one reason or another, I've simply swiped using coordinates to scroll down the page.

self.driver.swipe(100, 700, 100, 150)
Eric
  • 159
  • 2
  • 11