整个九宫格是一个 view
self.driver.find_element_by_id("com.elc:id/gesturepwd_create_lockview")
width = 640-80 width 等于 560
height = 1048-488 height 等于 560
九宫格是正方形
p11 = int(x + width / 6), int(y + height / 6)
(173, 581)
定位方式存在一个字典中
a = {
"解锁提示": "com.elc:id/gesturepwd_create_text",
"九宫格": "com.elc:id/gesturepwd_create_lockview",
"继续": "com.elc:id/right_btn",
}
lock_pattern = self.driver.find_element_by_id(a["九宫格"])
x = lock_pattern.location.get('x')
y = lock_pattern.location.get('y')
width = lock_pattern.size.get('width')
height = lock_pattern.size.get('height')
print(x, y, width, height)
offset = width / 6
p11 = int(x + width / 6), int(y + height / 6)
p12 = int(x + width / 2), int(y + height / 6)
p13 = int(x + width - offset), int(y + height / 6)
p21 = int(x + width / 6), int(y + height / 2)
p22 = int(x + width / 2), int(y + height / 2)
p23 = int(x + width - offset), int(y + height / 2)
p31 = int(x + width / 6), int(y + height - offset)
p32 = int(x + width / 2), int(y + height - offset)
p33 = int(x + width - offset), int(y + height - offset)
print(p11, p12, p13)
print(p21, p22, p23)
print(p31, p32, p33)
80 488 560 560 # 九宫格坐标值 与上面计算的一样
(173, 581) (360, 581) (546, 581)
(173, 768) (360, 768) (546, 768)
(173, 954) (360, 954) (546, 954)
p3 = p13[0] - p11[0] # 偏移的值是 373
TouchAction(self.driver).press(x=p11[0], y=p11[1]).move_to(x=p3, y=0).wait(1000).move_to(x=0, y=p3).wait(
1000).release().perform()
# 横向滑动
从 173 滑动到 546 坐标的偏移量是 546-173 = 373
第一个值不变 press(x=p11[0], y=p11[1]).move_to(x=373, y =0),因为 y 的值是相同的,就不变
# 纵向滑动
move_to(x=0, y=373) 因为 x 的值不变,移动 y 的值
九宫格是正方的形,所以 从第 1 点到 3 点是 373, 从 3 点到 9 点也是 373
这样的写法,不需要固定坐标值,根据不同的设备屏幕大小自动获取到 -- 偏移值
def login_unlock(self):
a = {
"解锁提示": "com.elc:id/gesturepwd_create_text",
"九宫格": "com.elc:id/gesturepwd_create_lockview",
"继续": "com.elc:id/right_btn",
}
unlock_text = self.driver.find_element_by_id(a["解锁提示"])
lock_pattern = self.driver.find_element_by_id(a["九宫格"])
x = lock_pattern.location.get('x')
y = lock_pattern.location.get('y')
width = lock_pattern.size.get('width')
height = lock_pattern.size.get('height')
print(unlock_text.text)
print(x, y, width, height)
offset = width / 6
p11 = int(x + width / 6), int(y + height / 6)
p12 = int(x + width / 2), int(y + height / 6)
p13 = int(x + width - offset), int(y + height / 6)
p21 = int(x + width / 6), int(y + height / 2)
p22 = int(x + width / 2), int(y + height / 2)
p23 = int(x + width - offset), int(y + height / 2)
p31 = int(x + width / 6), int(y + height - offset)
p32 = int(x + width / 2), int(y + height - offset)
p33 = int(x + width - offset), int(y + height - offset)
p3 = p13[0] - p11[0]
sleep(3)
TouchAction(self.driver).press(x=p11[0], y=p11[1]).move_to(x=p3, y=0).wait(1000).move_to(x=0, y=p3).wait(
1000).release().perform()
Vimeo