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?

4

3 回答 3

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.

于 2021-02-06T00:01:31.527 回答
0

过去,当我因为某种原因遇到滚动问题时,我只是使用坐标滑动来向下滚动页面。

self.driver.swipe(100, 700, 100, 150)
于 2018-01-23T14:33:38.710 回答
0

Appium Python 有一个原生scroll函数。它适用于 Android 和 iOS。

driver.scroll(origin_el, destination_el, duration=None),其中持续时间是可选参数。此功能滚动origin_el到 的位置destination_el

滚动源代码链接

Appium 文档参差不齐,需要更新。但是,源代码记录得很好,足以理解和学习该程序。

于 2019-03-28T19:08:18.777 回答