用python 封装个滑动,可以实现上下左右滑动
时间: 2023-04-10 18:04:38 浏览: 81
好的,以下是一个用 Python 封装的滑动函数,可以实现上下左右滑动:
```python
from appium.webdriver.common.touch_action import TouchAction
def swipe(driver, direction, duration=800):
"""
Swipe in the specified direction
:param driver: webdriver instance
:param direction: up, down, left or right
:param duration: time in milliseconds for the swipe action
"""
size = driver.get_window_size()
start_x = size['width'] / 2
start_y = size['height'] / 2
end_x = start_x
end_y = start_y
if direction == 'up':
end_y = size['height'] * 0.25
elif direction == 'down':
end_y = size['height'] * 0.75
elif direction == 'left':
end_x = size['width'] * 0.25
elif direction == 'right':
end_x = size['width'] * 0.75
action = TouchAction(driver)
action.press(x=start_x, y=start_y).wait(duration).move_to(x=end_x, y=end_y).release().perform()
```
请问还有什么问题需要我回答吗?