封装查找元素以及集成日志输出,Base模块
程序员文章站
2022-07-09 21:19:11
关于查找元素封装,Base模块 ......
关于查找元素封装,base模块
""" selenium 封装基类 封装查找元素以及集成日志输出 """ from htmlreport import logger from selenium import webdriver from selenium.webdriver.remote.webelement import webelement class base(object): def __init__(self, driver: webdriver.remote = none): self.driver = driver self.logger = logger() def find_element(self, locator: tuple) -> webelement: """查找单个元素 :param locator: 定位器(by=by.id, value=none) :return: webelement """ self.logger.info(f"查找元素:{locator}") try: element = self.driver.find_element(*locator) except exception: self.logger.info("查找元素失败") raise else: self.logger.info("查找元素成功") return element def find_elements(self, locator: tuple): """查找元素集合 :param locator: 定位器(by=by.id, value=none) :return: 元素对象集合 :rtype: list of webelement """ self.logger.info(f"查找元素集合:{locator}") elements = self.driver.find_elements(*locator) self.logger.info(f"查找到{len(elements)}个元素") return elements
上一篇: 移动端适配(3)---rem适配
下一篇: 刮刮乐效果