我正在尝试使用PywinAuto Lib进行UI自动化。 当我尝试时,多个UI元素具有相同的UI属性。 有什么办法,我们可以别名并确定我们需要什么。
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'}
答案 0 :(得分:2)
有几种方法:
在found_index=i
的搜索条件中使用child_window
。
使用children()
,但是0.6.x(计划用于未来的改进)中的过滤条件数量非常有限:class_name, control_type, content_only, title
。
使用Getting Started Guide -> How to know magic attribute names中的best_match
个搜索规则(建议阅读前几章)。