直接上代码吧:
from appium.webdriver.common.touch_action import TouchAction
from driver import AppiumTest
1
2 3 4 5 6 7 8 9 10
扫描二维码关注公众号,回复:
6233724 查看本文章
11 12 13 |
#手势密码 封装: 九宫格(012;345;678)手势为:1478 def gesturepassword(self): list_pwd = self.driver.find_elements_by_class_name( "android.widget.ImageView" ) TouchAction(self.driver).press(list_pwd[1]).move_to(list_pwd[1]).move_to(list_pwd[4]).wait(100).move_to(list_pwd[7]).wait(100).move_to(list_pwd[8]).release().perform() time.sleep(1) print( "输入手势密码" ) "" "如果为新注册,或者修改手势密码的时候,需要输入两次手势密码,如果只是登录的话就是一次" "" try : ee=self.driver.find_element_by_name( "请再绘制手势密码" ) list_pwd = self.driver.find_elements_by_class_name( "android.widget.ImageView" ) TouchAction(self.driver).press(list_pwd[1]).move_to(list_pwd[1]).move_to(list_pwd[4]).wait(100).move_to(list_pwd[7]).wait(100).move_to(list_pwd[8]).release().perform() except Exception: pass |
解释:
因为 九宫格 所有的店 都是一个 ImageView 而且 同属于android.widget.ImageView 这个 class ,所以 直接用self.driver.find_elements_by_class_name 这个方法 把 所有点都抓出来,存入list,这样
手机的 九个点 就可以 理解为 0 1 2 (list【】)
3 4 5
6 7 8
这种形式,然后调用TouchAction(self.driver).press.......这个方法 ,按照你想设定的轨迹走就可以了