【Appium】使用swipe函数,实现模拟屏幕上下左右滑动操作 您所在的位置:网站首页 苹果通知栏无法左右滑动设置 【Appium】使用swipe函数,实现模拟屏幕上下左右滑动操作

【Appium】使用swipe函数,实现模拟屏幕上下左右滑动操作

2024-06-16 07:50| 来源: 网络整理| 查看: 265

一、实现原理

1.swipe函数使用方法

driver.swipe(x1, y1, x2, y2, t)

(X1,Y1):滑动起始点的坐标

(X2,Y2):滑动结束点的坐标

t:完成滑动所需要的时间,单位为ms,默认为空,可不填。

2.由于不同尺寸的屏幕,长宽以及屏幕分辨率不同,因此滑动起始结束点的坐标使用屏幕比例的方式确定。

上下滑动:X点坐标为屏幕横向长度的50%,即屏幕中间,Y点坐标分别为屏幕高度的25%和75%,即屏幕的高度的1/4(A)处和3/4(B)处;

向下滑动,从A点滑到B点

向上滑动,从B点滑到A点

左右滑动:Y点坐标为屏幕竖向高度的50%,即屏幕中间,X点坐标分别为屏幕宽度的25%和75%,即屏幕的宽度的1/4(C)处和3/4(D)处;

向右滑动,从C点滑到D点

向左滑动,从D点滑到C点

二、实现代码 class Slide: def __init__(self, driver): self.driver = driver def get_screen_size(self): x = self.driver.get_window_size()['width'] # 获取屏幕宽度 y = self.driver.get_window_size()['height'] # 获取屏幕高度 return (x, y) def swipeLeft(self): l = self.get_screen_size() x1 = int(l[0] * 0.75) y1 = int(l[1] * 0.5) x2 = int(l[0] * 0.25) self.driver.swipe(x1, y1, x2, y1) print('向左滑动') def swipeRight(self): l = self.get_screen_size() x1 = int(l[0] * 0.25) y1 = int(l[1] * 0.5) x2 = int(l[0] * 0.75) self.driver.swipe(x1, y1, x2, y1) print('向右滑动') def swipeUp(self): l = self.get_screen_size() x1 = int(l[0] * 0.5) y1 = int(l[1] * 0.75) y2 = int(l[1] * 0.25) self.driver.swipe(x1,y1,x1,y2) print('向上滑动') def swipeDown(self): l = self.get_screen_size() x1 = int(l[0] * 0.5) y1 = int(l[1] * 0.25) y2 = int(l[1] * 0.75) self.driver.swipe(x1, y1, x1, y2) print('向下滑动')

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有