前言
控件操作完成后,一般需要获取控件的属性对结果断言,判断是否符合预期。
查看控件类型
wrapper_object() 方法可以查看控件类型
代码语言:javascript复制from pywinauto import Application 上海悠悠 wx:283340479 blog:https://www.cnblogs.com/yoyoketang/ app = Application('uia').start("notepad.exe")
win = app.window(title_re="无标题 - 记事本")
m = win.child_window(title="帮助(H)", control_type="MenuItem")
print(win.wrapper_object())
print(m.wrapper_object())
运行结果
代码语言:javascript复制uiawrapper.UIAWrapper - '无标题 - 记事本', Dialog
uia_controls.MenuItemWrapper - '帮助(H)', MenuItem
获取控件文本和class属性
获取文本属性和class属性
代码语言:javascript复制from pywinauto import Application
app = Application('uia').start("notepad.exe")
win = app.window(title_re="无标题 - 记事本")m = win.child_window(title="帮助(H)", control_type="MenuItem")# 获取文本属性print(win.texts())
print(m.texts())# 获取class 属性print(win.class_name())
print(m.class_name())
get_properties()
获取全部属性
from pywinauto import Application# 上海悠悠 wx:283340479#blog:https://www.cnblogs.com/yoyoketang/app = Application('uia').start("notepad.exe")
win = app.window(title_re="无标题 - 记事本")m = win.child_window(title="帮助(H)", control_type="MenuItem")# 获取文本属性print(win.texts())
print(m.texts())# 窗口、控件名称print(m.window_text())# 子控件个数print(m.control_count())# 获取class 属性print(win.get_properties())
print(m.get_properties())
运行结果
代码语言:javascript复制['无标题 - 记事本']
['帮助(H)']
帮助(H)
0
{'class_name': 'Notepad', 'friendly_class_name': 'Dialog', 'texts': ['无标题 - 记事本'], 'control_id': 11144239, 'rectangle': <RECT L141, T230, R918, B955>, 'is_visible': True, 'is_enabled': True, 'control_count': 3, 'is_keyboard_focusable': True, 'has_keyboard_focus': False, 'automation_id': ''}
{'class_name': '', 'friendly_class_name': 'MenuItem', 'texts': ['帮助(H)'], 'control_id': None, 'rectangle': <RECT L364, T261, R419, B280>, 'is_visible': True, 'is_enabled': True, 'control_count': 0, 'is_keyboard_focusable': True, 'has_keyboard_focus': False, 'automation_id': ''}