App自动化-九宫格绘制
from appium.webdriver.common.touch_action import TouchAction
class Base_page:
def __init__(self, driver):
self.driver = driver
def draw_lattice(self, element, location):
"""
九宫格绘制
:param element: 九宫格元素定位
:param location: 第几个点,传参要为列表,元组
:return:
"""
if len(location) < 5:
raise ValueError('location 需要至少5个元素')
size = element.rect
x = size['x']
y = size['y']
height = size['height']
width = size['width']
points = [
{'x': x + width / 6 * 1, 'y': y + height / 6 * 1},
{'x': x + width / 6 * 3, 'y': y + height / 6 * 1},
{'x': x + width / 6 * 5, 'y': y + height / 6 * 1},
{'x': x + width / 6 * 1, 'y': y + height / 6 * 3},
{'x': x + width / 6 * 3, 'y': y + height / 6 * 3},
{'x': x + width / 6 * 5, 'y': y + height / 6 * 3},
{'x': x + width / 6 * 1, 'y': y + height / 6 * 5},
{'x': x + width / 6 * 3, 'y': y + height / 6 * 5},
{'x': x + width / 6 * 5, 'y': y + height / 6 * 5}
]
action = TouchAction(self.driver)
action.press(**points[location[0] - 1]).wait(200)
for point in location[1:]:
action.move_to(**points[point - 1]).wait(200)
action.release().perform()