如何使用 pywinauto 从不可检测控件[编辑]的应用程序中获取文本?
How to get the text from an application which is a non detectable control[edit) using pywinauto?
我正在尝试使用 pywinauto 自动化我的应用程序。我想从一个只能读取和聚焦的编辑框中读取值。可以通过 pywinauto 实现吗?
这是我的代码:
dialog = Desktop(backend='uia')
win = dialog.window(title_re ="XXX_Decoder")
label=win.child_window(title="Debug Output",auto_id="debugConsoleGroupBox",control_type="Group")
label.child_window(auto_id="debugConsole", control_type="Edit").texts()
for win.print_control_identifiers() 得到的是:
Dialog - 'WRT BT Decoder' (L52, T52, R724, B430)
['WRT BT Decoder', 'Dialog', 'WRT BT DecoderDialog']
child_window(title="WRT BT Decoder", auto_id="WRT_BT_Decoders", control_type="Window")
|
|
| GroupBox - 'Debug Output' (L80, T257, R670, B370)
| ['Debug OutputGroupBox', 'GroupBox', 'Debug Output', 'GroupBox0', 'GroupBox1']
| child_window(title="Debug Output", auto_id="debugConsoleGroupBox", control_type="Group")
| |
| | Edit - '' (L100, T276, R644, B364)
| | ['', 'Edit', '0', '1', 'Edit0', 'Edit1']
| | child_window(auto_id="debugConsole", control_type="Edit")
| | |
| | | ScrollBar - 'Vertical' (L625, T278, R642, B362)
| | | ['ScrollBar', 'VerticalScrollBar', 'Vertical']
| | | child_window(title="Vertical", auto_id="NonClientVerticalScrollBar", control_type="ScrollBar")
| | | |
| | | | Button - 'Line up' (L625, T278, R642, B295)
| | | | ['Line up', 'Line upButton', 'Button2']
| | | | child_window(title="Line up", auto_id="UpButton", control_type="Button")
| | | |
| | | | Button - 'Line down' (L625, T345, R642, B362)
| | | | ['Line downButton', 'Line down', 'Button3']
| | | | child_window(title="Line down", auto_id="DownButton", control_type="Button")
|
在inspect.exe中:
LegacyIAccessible.Name: ""
LegacyIAccessible.Role: editable text (0x2A)
LegacyIAccessible.State: read only,focusable (0x100040)
是这样的。我怎样才能得到价值?
可以这样:
label.child_window(auto_id="debugConsole", control_type="Edit").iface_value.GetValue()
它将在未来的版本中添加为 .get_value()
方法。
我正在尝试使用 pywinauto 自动化我的应用程序。我想从一个只能读取和聚焦的编辑框中读取值。可以通过 pywinauto 实现吗?
这是我的代码:
dialog = Desktop(backend='uia')
win = dialog.window(title_re ="XXX_Decoder")
label=win.child_window(title="Debug Output",auto_id="debugConsoleGroupBox",control_type="Group")
label.child_window(auto_id="debugConsole", control_type="Edit").texts()
for win.print_control_identifiers() 得到的是:
Dialog - 'WRT BT Decoder' (L52, T52, R724, B430)
['WRT BT Decoder', 'Dialog', 'WRT BT DecoderDialog']
child_window(title="WRT BT Decoder", auto_id="WRT_BT_Decoders", control_type="Window")
|
|
| GroupBox - 'Debug Output' (L80, T257, R670, B370)
| ['Debug OutputGroupBox', 'GroupBox', 'Debug Output', 'GroupBox0', 'GroupBox1']
| child_window(title="Debug Output", auto_id="debugConsoleGroupBox", control_type="Group")
| |
| | Edit - '' (L100, T276, R644, B364)
| | ['', 'Edit', '0', '1', 'Edit0', 'Edit1']
| | child_window(auto_id="debugConsole", control_type="Edit")
| | |
| | | ScrollBar - 'Vertical' (L625, T278, R642, B362)
| | | ['ScrollBar', 'VerticalScrollBar', 'Vertical']
| | | child_window(title="Vertical", auto_id="NonClientVerticalScrollBar", control_type="ScrollBar")
| | | |
| | | | Button - 'Line up' (L625, T278, R642, B295)
| | | | ['Line up', 'Line upButton', 'Button2']
| | | | child_window(title="Line up", auto_id="UpButton", control_type="Button")
| | | |
| | | | Button - 'Line down' (L625, T345, R642, B362)
| | | | ['Line downButton', 'Line down', 'Button3']
| | | | child_window(title="Line down", auto_id="DownButton", control_type="Button")
|
在inspect.exe中:
LegacyIAccessible.Name: ""
LegacyIAccessible.Role: editable text (0x2A)
LegacyIAccessible.State: read only,focusable (0x100040)
是这样的。我怎样才能得到价值?
可以这样:
label.child_window(auto_id="debugConsole", control_type="Edit").iface_value.GetValue()
它将在未来的版本中添加为 .get_value()
方法。