四、Appium-python-UI自动化之页面-上下滑动、左右滑动swipe方法操作
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了四、Appium-python-UI自动化之页面-上下滑动、左右滑动swipe方法操作,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3009字,纯文字阅读大概需要5分钟。
内容图文
![四、Appium-python-UI自动化之页面-上下滑动、左右滑动swipe方法操作](/upload/InfoBanner/zyjiaocheng/645/25b2c1872b8945bc826e243213df8530.jpg)
1.首先看app中怎么划分横纵坐标
2.swipe函数
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 (int): x-coordinate at which to start start_y (int): y-coordinate at which to start end_x (int): x-coordinate at which to stop end_y (int): y-coordinate at which to stop duration (:obj:`int`, optional): time to take the swipe, in ms. Usage: driver.swipe(100, 100, 100, 400) Returns: `appium.webdriver.webelement.WebElement` """ # `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
解析:
swipe(self, start_x, start_y, end_x, end_y, duration=None)
swipe(开始横坐标,开始纵坐标,结束横坐标,结束纵坐标,持续的时间,单位毫秒)
重点:在执行swipe之前一定要强制sleep 3-4s,不然会出现:wipe did not complete successfully报错
3.各种滑动
3.1 因为每个手机的坐标可能都不一样,这里我们可以通过先获取手机屏幕的长和宽,然后再次计算需要滑动的坐标位置,
def get_myWindow_size(self): ''' 获取手机长宽 :return: ''' x = self.driver.get_window_size()['width'] # 获取x轴的长度 y = self.driver.get_window_size()['height'] # 获取y轴的长度 return x,y
3.2 向下滑动,即x轴不变,y轴减小
def swipeDown(self): ''' 页面向下滑动 :return: ''' size = self.get_myWindow_size() MyLog.logger().info("size :" +str(size[0])+','+str(size[1])) x1 = int(size[0] * 0.5) # size[0]取元组的第一个值,*0.5表示中间的点 y1 = int(size[1] * 3/4) # size[1]取元组的第二个值,*0.1表示距离底部近 y2 = int(size[1] * 1/6) time.sleep(4) self.driver.swipe(x1, y1, x1, y2, 1000)
3.3 向下滑动,即x轴不变,y轴增大
def swipeUp(self): ''' 页面向上滑动 :return: ''' size = self.get_myWindow_size() MyLog.logger().info("size :" +str(size[0])+','+str(size[1])) x1 = int(size[0] * 0.5) # size[0]取元组的第一个值,*0.5表示中间的点 y1 = int(size[1] * 1/6) # size[1]取元组的第二个值,*0.1表示距离底部近 y2 = int(size[1] * 3/4) time.sleep(4) self.driver.swipe(x1, y1, x1, y2, 1000)
3.4 向右滑动 ,即x减小,y轴不变
def swipRight(self): ''' 页面向右滑动 :return: ''' size = self.get_myWindow_size() MyLog.logger().info("size :" +str(size[0])+','+str(size[1])) x1 = int(size[0] * 0.5) # size[0]取元组的第一个值,*0.5表示中间的点
x2 = int(size[0] * 0.25) # size[0]取元组的第一个值,*0.5表示中间的点
y1 = int(size[1] * 3/4) # size[1]取元组的第二个值,*0.1表示距离底部近
y2 = int(size[1] * 1/6)
time.sleep(4) self.driver.swipe(x1, y1, x2, y1, 1000)
3.5 向左滑动,即x轴增大,y轴不变
def swipLeft(self): ''' 页面向左滑动 :return: ''' size = self.get_myWindow_size() MyLog.logger().info("size :" +str(size[0])+','+str(size[1])) x1 = int(size[0] * 0.25) # size[0]取元组的第一个值,*0.5表示中间的点 x2 = int(size[0] * 0.75) # size[0]取元组的第一个值,*0.5表示中间的点 y1 = int(size[1] * 3/4) # size[1]取元组的第二个值,*0.1表示距离底部近 y2 = int(size[1] * 1/6) time.sleep(4) self.driver.swipe(x1, y1, x2, y1, 1000)
内容总结
以上是互联网集市为您收集整理的四、Appium-python-UI自动化之页面-上下滑动、左右滑动swipe方法操作全部内容,希望文章能够帮你解决四、Appium-python-UI自动化之页面-上下滑动、左右滑动swipe方法操作所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。