|
直接上代碼吧: 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,這樣 手機(jī)的 九個點 就可以 理解為 0 1 2 (list【】) 3 4 5 6 7 8 這種形式,然后調(diào)用TouchAction(self.driver).press.......這個方法 ,按照你想設(shè)定的軌跡走就可以了
|