python九宫格滑动解锁

实现思路:

1.获取九宫格patterview的起始坐标x、y
2.获取九宫格patterview的宽度(width)、高度(height)
3.九宫格的九个格子大约平均把patterview的长、宽平均分成了4个等分,宽度间隔为width/4、高度间隔为height/4
4.第一个格子的坐标为(x+width/4, y+height/4)

5.每次滑动的时候,就相当于横坐标(纵坐标)的变化量△x为width/4(height/4
6.使用TouchAction、moveTo方法实现滑动即可

实现代码:

def test_cKabao(self): self.driver.find_element_by_id('cn.xxxx.xxxx.android:id/xxxx_tv_card_package').click() time.sleep(1) patterview = self.driver.find_element_by_id('cn.xxxx.xxxx.android:id/xxxx_card_pw_patterview') #获取九宫格控件 x = patterview.location.get('x') #九宫格的起始坐标x y = patterview.location.get('y') #九宫格的起始坐标y //获取九宫格的宽度、高度 width = patterview.size.get('width') #九宫格的宽度 height = patterview.size.get('height') #九宫格的高度 # print(x, y, width, height) xstep = width/4 #宽度间隔 ystep = height/4 #高度间隔 #九宫格第一个格子的坐标(即是九宫格的起始坐标) xStartPoint = x + xstep yStartPoint = y + ystep //使用TouchAction方法实现滑动解锁 TouchAction(self.driver).press(x=xStartPoint, y=yStartPoint).wait(1000).move_to(x=0, y=ystep).wait(1000).move_to(x=0, y=ystep).wait(1000).move_to(x=xstep, y=0).release().perform() time.sleep(5) RelativeLayout = self.driver.find_element_by_class_name('android.widget.RelativeLayout') RelativeLayout.find_element_by_id('cn.xxxx.xxxx.android:id/xxxx_base_iv_back').click() # self.driver.find_element_by_id('cn.xxxx.xxxx.android:id/xxxx_base_iv_back') print('test_cKabao 测试成功') time.sleep(3)

    原文作者:九宫格问题
    原文地址: https://blog.csdn.net/lykio_881210/article/details/78999631
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞