appium实现app上下左右滑动操作

生也有涯,知也无涯。这篇文章主要讲述appium实现app上下左右滑动操作相关的知识,希望能为你提供帮助。
【appium实现app上下左右滑动操作】1. swipe方法语法 

swipe(self, start_x, start_y, end_x, end_y, duration=None):参数 - start_x - 开始滑动的x坐标 - start_y - 开始滑动的y坐标 - end_x - 结束点x坐标 - end_y - 结束点y坐标 - duration - 持续时间,单位毫秒

2. 手机坐标:
手机从左上角开始为0,横着的是x轴,竖着的是y轴
appium实现app上下左右滑动操作

文章图片

3.  获取屏幕的size
size = driver.get_window_size()   
print (size)          # {\'width\': 1080, \'height\': 1920} ,返回字典类型,可使用字典的方法取width/height的值
print (size["width"])# 获取浏览器的宽度1080
print (size["height"])# 获取浏览器的高度1920
4. app上、下、左、右滑动方法
# coding:utf-8 from appium import webdriver from time import sleep desired_caps = { \'platformName\': \'android\', \'deviceName\': \'30d4e606\', \'platformVersion\': \'4.4.2\', # apk包名 \'appPackage\': \'com.taobao.taobao\', # apk的launcherActivity \'appActivity\': \'com.taobao.tao.welcome.Welcome\' } driver = webdriver.Remote(\'http://127.0.0.1:4723/wd/hub\', desired_caps)def swipeUp(driver, t=500, n=1): \'\'\'向上滑动屏幕\'\'\' l = driver.get_window_size() x1 = l[\'width\'] * 0.5# x坐标 y1 = l[\'height\'] * 0.75# 起始y坐标 y2 = l[\'height\'] * 0.25# 终点y坐标 for i in range(n): driver.swipe(x1, y1, x1, y2, t)def swipeDown(driver, t=500, n=1): \'\'\'向下滑动屏幕\'\'\' l = driver.get_window_size() x1 = l[\'width\'] * 0.5# x坐标 y1 = l[\'height\'] * 0.25# 起始y坐标 y2 = l[\'height\'] * 0.75# 终点y坐标 for i in range(n): driver.swipe(x1, y1, x1, y2,t)def swipLeft(driver, t=500, n=1): \'\'\'向左滑动屏幕\'\'\' l = driver.get_window_size() x1 = l[\'width\'] * 0.75 y1 = l[\'height\'] * 0.5 x2 = l[\'width\'] * 0.25 for i in range(n): driver.swipe(x1, y1, x2, y1, t)def swipRight(driver, t=500, n=1): \'\'\'向右滑动屏幕\'\'\' l = driver.get_window_size() x1 = l[\'width\'] * 0.25 y1 = l[\'height\'] * 0.5 x2 = l[\'width\'] * 0.75 for i in range(n): driver.swipe(x1, y1, x2, y1, t)if __name__ == "__main__": print(driver.get_window_size()) sleep(5) swipLeft(driver, n=2) sleep(2) swipRight(driver, n=2)

 

    推荐阅读