def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> 'WebDriver': """从一个点滑动到另一个点,可选择设置持续时间 参数: start_x: 开始滑动的 x 坐标 start_y: 开始滑动的 y 坐标 end_x: 结束滑动的 x 坐标 end_y: 结束滑动的 y 坐标 duration: 定义滑动速度,即从点 a 滑动到点 b 所需的时间,单位为毫秒。 用法: driver.swipe(100, 100, 100, 400) 返回: Union['WebDriver', 'ActionHelpers']: 返回自身实例 """ touch_input = PointerInput(interaction.POINTER_TOUCH, 'touch') actions = ActionChains(self.driver) actions.w3c_actions = ActionBuilder(self.driver, mouse=touch_input) actions.w3c_actions.pointer_action.move_to_location(start_x, start_y) actions.w3c_actions.pointer_action.pointer_down() if duration > 0: actions.w3c_actions = ActionBuilder(self.driver, mouse=touch_input, duration=duration) actions.w3c_actions.pointer_action.move_to_location(end_x, end_y) actions.w3c_actions.pointer_action.release() actions.perform() return cast('WebDriver', self)
appium2.0 + appium-python-client + swipe
于 2024-03-13 17:40:35 首次发布