Python Appium 滑动、点击等操作
1、手机滑动-swipe
#FileName : Tmall_App.py#Author : Adil#DateTime : 2018/3/25 17:22#SoftWare : PyCharm
from appium importwebdriver
caps={}
caps['platformName'] = 'Android'caps['platformVersion'] = '6.0'caps['deviceName'] = 'N79SIV5PVCSODAQC'caps['appPackage'] = 'com.tmall.wireless'caps['appActivity'] = 'com.tmall.wireless.splash.TMSplashActivity'
#隐藏键盘
caps['unicodeKeyboard'] =True
caps['resetKeyboard'] =True
driver= webdriver.Remote('http://127.0.0.1:4723/wd/hub', caps)
driver.swipe()if __name__ == '__main__':pass
查看源码
Ctrl + 鼠标右键点击 driver.swipe()
#convenience method added to Appium (NOT Selenium 3)
def swipe(self, start_x, start_y, end_x, end_y, duration=None):"""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 - (optional) time to take the swipe, in ms.
:Usage:
driver.swipe(100, 100, 100, 400)"""
#`swipe` is something like press-wait-move_to-release, which the server
#will translate into the correct action
action =TouchAction(self)
action \
.press(x=start_x, y=start_y) \
.wait(ms=duration) \
.move_to(x=end_x, y=end_y) \
.release()
action.perform()return self
查看源码语法,起点和终点四个坐标参数。 手机屏幕从左上角开始为0,向右为x轴坐标,向下为y轴坐标。
duration是滑动屏幕持续的时间,时间越短速度越快。默认为None可不填,一般设置500-1000毫秒比较合适。
swipe(self, start_x, start_y, end_x, end_y, duration=None)
Swipefrom one point to another point