appium-python-client 4.0版本废弃MultiAction and TouchAction

265 阅读2分钟

引用官方文档:pypi.org/project/App…

image.png


from appium.webdriver.extensions.action_helpers import ActionHelpers

"""Drag the origin element to the destination element

        Args:
            origin_el: the element to drag
            destination_el: the element to drag to
            pause: how long the action pauses before moving after the tap and hold, in float seconds.

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
"""
driver.drag_and_drop(origin_el, destination_el, pause = 2.0)
# 如果想要长按也可以使用这个方法,origin_el、destination_el填写同一个元素就可以了


"""Scrolls from one element to another

        Args:
            origin_el: the element from which to begin scrolling (center of element)
            destination_el: the element to scroll to (center of element)
            duration: defines speed of scroll action when moving from originalEl to destinationEl.
                Default is 600 ms for W3C spec.

        Usage:
            driver.scroll(el1, el2)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        """

driver.scroll(origin_el,destination_el,duration=2000)
#duration不填写默认是600ms,从一个元素滚动到另一个元素

"""Taps on an particular place with up to five fingers, holding for a
        certain time

        Args:
            positions: an array of tuples representing the x/y coordinates of
                the fingers to tap. Length can be up to five.
            duration: length of time to tap, in ms

        Usage:
            driver.tap([(100, 20), (100, 60), (100, 100)], 500)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        """
driver.tap([(100, 20), (100, 60), (100, 100)], 500)



"""Swipe from one point to another point, for an optional duration.

        Args:
            start_x: x-coordinate at which to start
            start_y: y-coordinate at which to start
            end_x: x-coordinate at which to stop
            end_y: y-coordinate at which to stop
            duration: defines the swipe speed as time taken to swipe from point a to point b, in ms.

        Usage:
            driver.swipe(100, 100, 100, 400)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        """
     #从一个点滑动到另一个点,持续时间可选    
      driver.swipe(100, 100, 100, 400,2000)
        
   """Flick from one point to another point.

        Args:
            start_x: x-coordinate at which to start
            start_y: y-coordinate at which to start
            end_x: x-coordinate at which to stop
            end_y: y-coordinate at which to stop

        Usage:
            driver.flick(100, 100, 100, 400)

        Returns:
            Union['WebDriver', 'ActionHelpers']: Self instance
        """      
    #从一个点到另一个点,快速的
      driver.flick(100, 100, 100, 400)