使用 Pywinauto 库,您可以轻松打印出窗口的子元素以及它们的属性。以下示例代码展示了如何打印所有子元素或特定控件的子元素信息。

from pywinauto import Application

app = Application().start('notepad.exe')
dlg = app.UntitledNotepad

# 打印所有子元素
print(dlg.print_control_identifiers())

# 打印指定控件的子元素
edit = dlg.Edit
print(edit.print_control_identifiers())

在上述示例代码中,我们启动了记事本程序,并获取了它的窗口对象。使用 print_control_identifiers() 方法可以打印出窗口的子元素以及它们的属性和值,包括控件类型、控件名称、控件类名称、控件位置和大小等信息。

如果要打印指定控件的子元素,可以先获取该控件对象,然后调用 print_control_identifiers() 方法。在上述示例代码中,我们获取了编辑框控件的对象,并打印了它的子元素信息。

Pywinauto 打印窗口子元素:使用示例代码获取控件信息

原文地址: https://www.cveoy.top/t/topic/mSNs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录