如何解决PyWinAuto –如何自动选择组合框
我试图在Win32应用程序的组合框中自动更改默认选择。
在屏幕保护程序处于活动状态时,自动化必须起作用。
默认选择是“选择2” 我需要将其更改为“选择1”
由于某种原因,我无论如何都无法使用组合框的属性或方法来更改选择。
只能按下组合框下拉按钮,然后发送{“ UP”}击键来更改选择。
以下代码在屏幕保护程序处于非活动状态时起作用。
但是当屏幕保护程序处于活动状态时,最后一行会生成一条错误消息 因为当窗口处于非活动状态时,type_keys方法不起作用。
在这种情况下,有必要使用send_keystrokes或send_chars,但不幸的是这些都不起作用。
是否可以以任何方式更改代码 ,以便可以在组合框中从“选择2”切换到“选择1”?
代码:
from pywinauto.application import Application
app = Application().connect(title_re=".*My App")
dlg_child_window = app.top_window()
dlg_toolbar = dlg_child_window['My Toolbar']
dlg_toolbar.ComboBox0.Button0.click()
app.top_window().type_keys("{UP}")
工具栏的print_control_identifiers打印输出,其中包含组合框和其下方的下拉按钮。
dlg_toolbar.print_control_identifiers()
Control Identifiers:
TYToolBar - 'My Toolbar' (L528,T127,R701,B163)
['My Toolbar','TYToolBar','My ToolbarTYToolBar']
child_window(title="'My Toolbar",class_name="TYToolBar")
|
| ComboBox - 'Selection 2' (L539,T134,R699,B155)
| ['ComboBox','ComboBox0','ComboBox1']
| child_window(title="Selection 2",class_name="TMCComboBox")
| |
| | Button - '' (L541,T136,R557,B153)
| | ['Button','Button0','Button1']
| | child_window(class_name="TComboButton")
|
| Button - '' (L541,B153)
| ['Button','Button1']
| child_window(class_name="TComboButton")
|
| ComboBox - 'Invisible Combo' (L539,R713,B155)
| ['ComboBox2']
| child_window(title="Invisible Combo",B153)
| | ['Button2']
| | child_window(class_name="TComboButton")
|
| Button - '' (L541,B153)
| ['Button2']
| child_window(class_name="TComboButton")
组合框属性:
dlg_toolbar.ComboBox0.get_properties()
{'class_name': 'TMCComboBox','friendly_class_name': 'ComboBox','texts': ['Selection 2'],'control_id': 660246,'rectangle': <RECT L539,B155>,'is_visible': True,'is_enabled': True,'control_count': 1,'style': 1442906308,'exstyle': 29184,'user_data': 0,'context_help_id': 0,'fonts': [<LOGFONTW 'MS Sans Serif' -11>],'client_rects': [<RECT L0,T0,R156,B17>],'is_unicode': False,'menu_items': [],'automation_id': '','selected_index': 0,'dropped_rect': <RECT L-539,T-134,R-539,B-134>}
按钮属性:
dlg_toolbar.ComboBox0.Button0.get_properties()
{'class_name': 'TComboButton','friendly_class_name': 'Button','texts': [''],'control_id': 1971292,'rectangle': <RECT L541,B153>,'control_count': 0,'style': 1409286144,'exstyle': 28672,'fonts': [<LOGFONTW 'MS Shell Dlg' -11>],R16,'automation_id': ''}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。