操作"/>
Appium定位之手机特有操作
-
滑动操作
思路:
1.点击取消更新,不点击跳过
2.获取屏幕尺寸
3.x1>x2,y1=y2
x1=屏幕尺寸的宽*0.9
x2=屏幕尺寸的宽*0.1
y1=y2=y*0.5
# -*- codeing = utf-8 -*-
# @Time : 2022/3/31 19:52
# @Author :su
# @File : ky_left_slip.py
# @Software : PyCharm
from time import sleepfrom testcase.kyCapability import check_cancelBtn, kydriver#公共业务
check_cancelBtn()#定义函数,获取屏幕尺寸
def get_size():x = kydriver.get_window_size()['width']y = kydriver.get_window_size()['height']print(x,y)return x,y
get_size()#定义函数,滑动操作
def swipeLeft():ll = get_size()#ll[0]代表屏幕尺寸x轴#ll[1]代表屏幕尺寸y轴x1 = int(ll[0]*0.9)x2 = int(ll[0]*0.1)y1 = int(ll[1]*0.5)y2 = y1# 5个参数# 第一个和第二个:起始坐标# 第三个和第四个:结束坐标# 第五个:滑动消耗的时间毫秒kydriver.swipe(x1,y1,x2,y2,1000)# 滑动两次
for i in range(2):swipeLeft()sleep(1)
2. 拖动操作
TouchAction(webdriver)对象,提供方法:
- press():按压某一个坐标点(x,y)
- tap():点击
- longpress():长按压
- move_to():移动坐标点
- wait():等待时间操作
- release():释放
- perform():执行
举例:九宫格解锁
# -*- codeing = utf-8 -*-
# @Time : 2022/3/31 20:24
# @Author :su
# @File : suishouji_touchAction.py
# @Software : PyCharm
from appium import webdriverdesired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '9'
desired_caps['deviceName'] = '127.0.0.1:62025'
#安装app
desired_caps['app'] = r'F:\mymoney.apk'
desired_caps['appPackage'] = 'com.mymoney'
desired_caps['appActivity'] = 'com.mymoney.biz.splash.SplashScreenActivity'
desired_caps['noReset'] = 'false'
# webdriver对象连接appium服务端
modriver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
更多推荐
Appium定位之手机特有操作
发布评论