分享

python--appium手势密码

 小猪窝969 2018-12-10

直接上代码吧:

from appium.webdriver.common.touch_action import TouchAction
from driver import AppiumTest
1
2
3
4
5
6
7
8
9
10
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.......这个方法 ,按照你想设定的轨迹走就可以了

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多