UI映射分析器。
ui-map-parser的Python项目详细描述
库,帮助您在文件中存储ui元素
安装方法:
pip install ui-map-parser
使用方法:
首先,您应该创建一个文件夹,您将用选择器在其中存储ini文件。 在此文件夹中创建公用.ini文件。 现在您可以在这个文件中创建元素,或者创建另一个表示页面的ini文件。在
示例公用.ini公司名称:
[DEFAULT]type=xpath[SimpleXpathElement]selector=//div[SimpleCssElement]type=cssselector=div#some-id
如何访问这些元素的示例:
^{pr2}$例如,您可以添加另一个页面登录名.ini公司名称:
[DEFAULT]type=xpath[EmailTextField]selector=//div[@id="login-panel"]/input[@id="email"][PasswordTextField]selector=//div[@id="login-panel"]/input[@id="password"]
然后按以下方式访问:
selector_type,selector=ui_map_parser.parse_element('Login.EmailTextField')
您可以使用“parent”属性替换重复节,如“//div[@id=“login panel”]”:
[DEFAULT]type=xpath[LoginPanel]selector=//div[@id="login-panel"][EmailTextField]parent=Login.LoginPanelselector=/input[@id="email"][PasswordTextField]parent=Login.LoginPanelselector=/input[@id="password"]
parent=Login.LoginPanel
表示正在搜索中的父元素登录名.ini名为“LoginPanel”的文件。
如果父元素位于“默认页面”(公用.ini默认情况下)您可以跳过此操作,而无需指定页面parent=LoginPanel
。在
重要注意:只能对具有相同类型的元素使用父级
要使用更复杂的元素模板,可以在选择器中指定模板:
[RegionButtonTemplate]type=xpathselector=//input[@id="region-%%region%%-button"]
然后像这样使用它:
selector_type,selector=ui_map_parser.parse_element('Login.RegionButtonTemplate',template={'region':'na'})# selector will be equal to "//input[@id="region-na-button"]"
您还可以为不同的语言指定选择器:
[SomeElement]type=xpathselector=//diven=[text()="some en text"]es=[text()="some es text"]
然后在初始化UIMapParser时指定语言:
ui_map_parser=UIMapParser(ini_files_folder,language='en')selector_type,selector=ui_map_parser.parse_element('SomeElement')# selector will be equal to "//div[text()="some en text"]"
- 项目
标签: