zoukankan      html  css  js  c++  java
  • App自动化-九宫格绘制

    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个元素')
            # 获取九宫格元素起始点坐标,返回字典形式如:{'height': 900, 'width': 900, 'x': 90, 'y': 545}
            size = element.rect
            # 起始点x坐标
            x = size['x']
            # 起始y坐标
            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()
    
    
    if __name__ == '__main__':
        print(__name__)
    
  • 相关阅读:
    C#面向对象
    C#语句
    C#语言数据类型
    Jupyter Notebook(iPython)
    BeautifulSoup模块
    requests模块
    爬虫基本原理
    版本控制系统
    支付宝支付
    django内置组件——ContentTypes
  • 原文地址:https://www.cnblogs.com/zhouxiongjie/p/12436186.html
Copyright © 2011-2022 走看看