app九宫格手势密码操作

import time

from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver import Remote
caps={
"platformName":"Android",
"deviceName":"127.0.0.1:7555",
"platformVersion":"6.0.1",
"appPackage":"com.xxzb.fenwoo",
"noSet":True,
"appActivity":"com.xxzb.fenwoo.activity.addition.WelcomeActivity"
}

driver=Remote(command_executor='http://127.0.0.1:4723/wd/hub',desired_capabilities=caps)
driver.implicitly_wait(20)
# 直接跳转到手势密码设置的页面
driver.start_activity('com.xxzb.fenwoo',".activity.user.CreateGesturePwdActivity")
action=TouchAction(driver)
time.sleep(2)
button=driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.Button").textContains("确定").resourceId("com.xxzb.fenwoo:id/right_btn")')
button.click()
time.sleep(2)
# 获取元素的起始坐标,元素的长度
e=driver.find_element_by_android_uiautomator('new UiSelector().className("android.view.View").resourceId("com.xxzb.fenwoo:id/gesturepwd_create_lockview")')
# 同时获取元素的起始点的x,y,height,width
start_x = e.rect["x"]
start_y = e.rect["y"]
width = e.rect["width"]
height = e.rect["height"]


point1 = {"x": start_x + width * 1 / 6, "y": start_y + height * 1 / 6}
point2 = {"x": start_x + width * 3 / 6, "y": start_y + height * 1 / 6}
point3 = {"x": start_x + width * 5 / 6, "y": start_y + height * 1 / 6}
point4 = {"x": start_x + width * 1 / 6, "y": start_y + height * 3 / 6}
point5= {"x": start_x + width * 3 / 6, "y": start_y + height * 3 / 6}
point6 = {"x": start_x + width * 5 / 6, "y": start_y + height * 3 / 6}
point7= {"x": start_x + width * 1 / 6, "y": start_y + height * 5 / 6}
point8= {"x": start_x + width * 3 / 6, "y": start_y + height * 5 / 6}
point9 = {"x": start_x + width * 5 / 6, "y": start_y + height * 5 / 6}



action.press(**point1).wait(10).move_to(
**point2).wait(10).move_to(
**point3).wait(10).move_to(
**point5).wait(10).move_to(
**point7).wait(10).move_to(
**point8).wait(10).move_to(
**point9).release().perform()


time.sleep(10)
driver.quit()
原文地址:https://www.cnblogs.com/fyangq/p/12673625.html