def childConfigXML(self, Pageskeyword, UIElementkeyword): confFile = self.rootChildConfigPath() config2 = Config("XMLFilePath", confFile) filepath = config2.get_path_config("uimptreekids") filepath = SystemOs().sys_path(filepath) xmlspath = XmlUtil(filepath) # 获取XML中相关信息 xmls = xmlspath.xml_parsing(Pageskeyword, UIElementkeyword) return xmls
def read_xml(self,Pageskeyword,UIElementkeyword): """ 获取data.yaml "firstpage"信息-->指向xml,读取xml中相关的配置信息 :param Pageskeyword: 如:首页 :param UIElementkeyword: 如: 客户管理 :return: """ myinfo_path = self.myinfo_path_info() filepath = SystemOs().sys_path(myinfo_path["myinfo"]["xml"]) #获取xml绝对路径 xmlspath = XmlUtil(filepath) # 获取XML中相关信息 xmls = xmlspath.xml_parsing(Pageskeyword, UIElementkeyword) return xmls
class UiElement: def __init__(self, driver, logger): self.driver = driver self.Xml = XmlUtil(Config().xml_filepath) self.logger = logger def getVisibleElement(self, by, value): """ 根据by和value进行定位 :param by: :param value: :return: """ wait = WebDriverWait(self.driver, 20, 0.5) locator = None if by == "id": locator = (By.ID, value) elif by == "name": locator = (By.NAME, value) elif by == "className": locator = (By.CLASS_NAME, value) elif by == "tagName": locator = (By.TAG_NAME, value) elif by == "linkText": locator = (By.LINK_TEXT, value) elif by == "partialLinkText": locator = (By.PARTIAL_LINK_TEXT, value) elif by == "cssSelector": locator = (By.CSS_SELECTOR, value) elif by == "xpath": locator = (By.XPATH, value) else: print("定位元素不存在", by, value) # 显示等待 web_element = wait.until(EC.visibility_of_element_located(locator)) return web_element def getElementByKeyword(self, page_keyword, ui_keyword): """ 根据传入的page_keyword与ui_keyword 从 UILibrary.xml 里找对应的by跟value :param page_keyword:要定位的页面 :param ui_keyword:要定位的元素 :return:返回定位方式以及定位用的值 """ by, value = self.Xml.xml_parsing(page_keyword, ui_keyword) self.logger.info("通过【%s】方式,值是【%s】定位【%s】的【%s】", by, value, page_keyword, ui_keyword) web_element = self.getVisibleElement(by, value) return web_element
def __init__(self, driver, logger): self.driver = driver self.Xml = XmlUtil(Config().xml_filepath) self.logger = logger