当多个 UI 元素具有相同的 UI 元素时,如何识别 UI 元素
How to identify UI elements when multiple UI elements have same UI elements
我正在尝试 UI 使用 PywinAuto Lib 实现自动化。
当我尝试时,多个 UI 元素具有相同的 UI Attributes 。
有什么办法,我们可以别名并确定我们需要什么。
ControlType: RadioButtonControl ClassName: RadioButton AutomationId: checkBox1 Rect: (805, 259, 855, 287) Name: Handle: 0x0(0) Depth: 7 CurrentIsSelected: True
ControlType: RadioButtonControl ClassName: RadioButton AutomationId: checkBox1 Rect: (858, 259, 908, 287) Name: Handle: 0x0(0) Depth: 7 CurrentIsSelected: False
如我们所见,我们看到两个 UI 元素具有相同的 UI 属性。一种交易方式是,我们可以返回 UI 开发并更改内容。
但是我们有什么办法可以对 .
selectButton = app1.Dialog.child_window(auto_id="checkBox1",control_type="RadioButton")
selectButton .click_input(button='left')
当我们 运行 时,我们看到了这个错误。
pywinauto.findwindows.ElementAmbiguousError: There are 3 elements that match the criteria {'auto_id': 'checkBox1', 'control_type': 'RadioButton', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'Ui automation', Window, 339012>, 'backend': 'uia'}
有几种方法:
在 child_window
的搜索条件中使用 found_index=i
。
使用children()
但0.6.x中的过滤条件数量非常有限(计划未来改进):class_name, control_type, content_only, title
.
使用Getting Started Guide -> How to know magic attribute names中的best_match
搜索规则(推荐阅读之前的章节)
我正在尝试 UI 使用 PywinAuto Lib 实现自动化。 当我尝试时,多个 UI 元素具有相同的 UI Attributes 。 有什么办法,我们可以别名并确定我们需要什么。
ControlType: RadioButtonControl ClassName: RadioButton AutomationId: checkBox1 Rect: (805, 259, 855, 287) Name: Handle: 0x0(0) Depth: 7 CurrentIsSelected: True
ControlType: RadioButtonControl ClassName: RadioButton AutomationId: checkBox1 Rect: (858, 259, 908, 287) Name: Handle: 0x0(0) Depth: 7 CurrentIsSelected: False
如我们所见,我们看到两个 UI 元素具有相同的 UI 属性。一种交易方式是,我们可以返回 UI 开发并更改内容。
但是我们有什么办法可以对 .
selectButton = app1.Dialog.child_window(auto_id="checkBox1",control_type="RadioButton")
selectButton .click_input(button='left')
当我们 运行 时,我们看到了这个错误。
pywinauto.findwindows.ElementAmbiguousError: There are 3 elements that match the criteria {'auto_id': 'checkBox1', 'control_type': 'RadioButton', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'Ui automation', Window, 339012>, 'backend': 'uia'}
有几种方法:
在
child_window
的搜索条件中使用found_index=i
。使用
children()
但0.6.x中的过滤条件数量非常有限(计划未来改进):class_name, control_type, content_only, title
.使用Getting Started Guide -> How to know magic attribute names中的
best_match
搜索规则(推荐阅读之前的章节)