pywinauto自动化控制
作者:互联网
Windows窗口检测工具:WinSpy、Spy++
1.pywinauto - MdxBuilder 3.0 RC1
程序:MdxBuilder 3.0 RC1.exe
from pywinauto.application import Application
##### process:
#app = Application().connect(title_re="MdxBuilder", class_name="#32770")
#app = pywinauto.application.Application().connect(title_re="MdxBuilder", class_name="Dialog")
#32770 (Dialog)
#app = Application().connect(process=2341)
##### handle:
#app = Application().connect(handle=0x010f0c)
##### path:
app = Application().connect(path="MdxBuilder 3.0 RC1.exe")
'''
<class 'pywinauto.application.Application'>
| window(self, **kwargs)
| Return a window of the application
|
| You can specify the same parameters as findwindows.find_windows.
| It will add the process parameter to ensure that the window is from
| the current process.
|
| See :py:func:`pywinauto.findwindows.find_elements` for the full parameters description.
|
'''
dlg = app.window()
#<class 'pywinauto.application.WindowSpecification'>
dlg["Edit4"].set_text("第4个输入框")
dlg["Edit3"].set_text('第3个输入框')
dlg["SourceEdit"].set_text("第1个输入框") # set_text:重置文本
dlg["TargetEdit"].type_keys('第2个输入框') # type_keys:追加输入文本 SendKeys() 表示模拟按键
#dlg.print_control_identifiers()
'''
#<class 'pywinauto.application.WindowSpecification'>
| Edit - '' (L1150, T208, R1649, B237)
| ['SourceEdit', 'Edit', 'Edit0', 'Edit1']
| child_window(class_name="Edit")
类:Edit
描述(title/Caption): ''
实例名(多个):['SourceEdit', 'Edit', 'Edit0', 'Edit1']
Control Identifiers:
Dialog - 'MdxBuilder' (L1038, T153, R1783, B941)
['Dialog', 'MdxBuilder', 'MdxBuilderDialog']
child_window(title="MdxBuilder", class_name="#32770")
|
| Edit - '' (L1150, T208, R1649, B237) # 第1个输入框
| ['SourceEdit', 'Edit', 'Edit0', 'Edit1']
| child_window(class_name="Edit")
|
| Button - '...' (L1671, T210, R1746, B239)
| ['Button', '...', '...Button', 'Button0', 'Button1', '...0', '...1', '...Button0', '...Button1']
| child_window(title="...", class_name="Button")
|
| Edit - '' (L1150, T244, R1649, B273) # 第2个输入框
| ['TargetEdit', 'Edit2']
| child_window(class_name="Edit")
|
| Button - '...' (L1671, T246, R1746, B275)
| ['Button2', '...2', '...Button2']
| child_window(title="...", class_name="Button")
|
| Edit - '' (L1150, T280, R1649, B309) # 第3个输入框
| ['StyleEdit', 'Edit3']
| child_window(class_name="Edit")
|
| Button - '...' (L1671, T280, R1746, B309)
| ['Button3', '...3', '...Button3']
| child_window(title="...", class_name="Button")
|
| Edit - '' (L1150, T318, R1649, B347)
| ['DataEdit', 'Edit4']
| child_window(class_name="Edit")
|
| Button - '...' (L1674, T318, R1749, B347)
| ['Button4', '...4', '...Button4']
| child_window(title="...", class_name="Button")
|
| ComboBox - 'MDict(Compact HTML)' (L1194, T374, R1382, B400)
| ['Original formatComboBox', 'ComboBox', 'ComboBox0', 'ComboBox1']
| child_window(title="MDict(Compact HTML)", class_name="ComboBox")
| |
| | Edit - 'MDict(Compact HTML)' (L1198, T378, R1357, B397)
| | ['Original formatEdit', 'Edit5']
| | child_window(title="MDict(Compact HTML)", class_name="Edit")
|
| Edit - 'MDict(Compact HTML)' (L1198, T378, R1357, B397)
| ['Original formatEdit', 'Edit5']
| child_window(title="MDict(Compact HTML)", class_name="Edit")
|
| ComboBox - 'GBK' (L1516, T374, R1692, B400)
| ['EncodingComboBox', 'ComboBox2']
| child_window(title="GBK", class_name="ComboBox")
| |
| | Edit - 'GBK' (L1520, T378, R1668, B397)
| | ['EncodingEdit', 'Edit6']
| | child_window(title="GBK", class_name="Edit")
|
| Edit - 'GBK' (L1520, T378, R1668, B397)
| ['EncodingEdit', 'Edit6']
| child_window(title="GBK", class_name="Edit")
|
| CheckBox - 'Key case sensitive' (L1094, T405, R1229, B425)
| ['Key case sensitiveCheckBox', 'CheckBox', 'Key case sensitive', 'CheckBox0', 'CheckBox1']
| child_window(title="Key case sensitive", class_name="Button")
|
| CheckBox - 'Allow export to text' (L1273, T405, R1422, B425)
| ['Allow export to text', 'CheckBox2', 'Allow export to textCheckBox']
| child_window(title="Allow export to text", class_name="Button")
|
| CheckBox - 'Right to left text' (L1461, T405, R1595, B425)
| ['CheckBox3', 'Right to left textCheckBox', 'Right to left text']
| child_window(title="Right to left text", class_name="Button")
|
| CheckBox - 'Strip Key' (L1626, T405, R1722, B425)
| ['CheckBox4', 'Strip Key', 'Strip KeyCheckBox']
| child_window(title="Strip Key", class_name="Button")
|
| Edit - 'Title (No HTML code allowed)' (L1134, T435, R1729, B460)
| ['TitleEdit', 'Edit7']
| child_window(title="Title (No HTML code allowed)", class_name="Edit")
|
| Edit - '<font size=5 color=red>Paste the description of this product in HTML source code format here</font>' (L1258, T465, R1731, B526)
| ["Description\n( Can be viewed in MDict by lookup ':About' )Edit", 'Edit8']
| child_window(title="<font size=5 color=red>Paste the description of this product in HTML source code format here</font>", class_name="Edit")
|
| CheckBox - 'Build Data archive only' (L1090, T569, R1246, B589)
| ['Build Data archive only', 'CheckBox5', 'Build Data archive onlyCheckBox']
| child_window(title="Build Data archive only", class_name="Button")
|
| Edit - '32' (L1446, T563, R1480, B588)
| ['Index block size(K)Edit', 'Edit9']
| child_window(title="32", class_name="Edit")
|
| Edit - '64' (L1686, T563, R1719, B588)
| ['Record block size(K)Edit', 'Edit10']
| child_window(title="64", class_name="Edit")
|
| Edit - '' (L1190, T633, R1400, B662)
| ['Encryption KeyEdit', 'Edit11']
| child_window(class_name="Edit")
|
| RadioButton - 'Email' (L1539, T636, R1613, B656)
| ['RadioButton', 'EmailRadioButton', 'Email', 'RadioButton0', 'RadioButton1']
| child_window(title="Email", class_name="Button")
|
| RadioButton - 'Device ID' (L1623, T634, R1706, B659)
| ['Device IDRadioButton', 'RadioButton2', 'Device ID']
| child_window(title="Device ID", class_name="Button")
|
| Edit - '' (L1093, T698, R1726, B834)
| ['EncryptEdit', 'Edit12']
| child_window(class_name="Edit")
|
| Progress - '' (L1203, T844, R1633, B869)
| ['StatusProgress', 'Progress']
| child_window(class_name="msctls_progress32")
|
| Button - 'Start' (L1206, T890, R1300, B923)
| ['Button5', 'Start', 'StartButton']
| child_window(title="Start", class_name="Button")
|
| Button - 'Quit' (L1368, T890, R1462, B923)
| ['Button6', 'Quit', 'QuitButton']
| child_window(title="Quit", class_name="Button")
|
| Button - 'About' (L1533, T890, R1627, B923)
| ['About', 'Button7', 'AboutButton']
| child_window(title="About", class_name="Button")
|
| Static - 'Source' (L1079, T214, R1123, B230)
| ['Static', 'Source', 'SourceStatic', 'Static0', 'Static1']
| child_window(title="Source", class_name="Static")
|
| Static - 'Target' (L1079, T248, R1120, B264)
| ['Static2', 'TargetStatic', 'Target']
| child_window(title="Target", class_name="Static")
|
| Static - 'Style' (L1083, T286, R1116, B302)
| ['Static3', 'StyleStatic', 'Style']
| child_window(title="Style", class_name="Static")
|
| Static - 'Data' (L1083, T324, R1113, B340)
| ['Static4', 'DataStatic', 'Data']
| child_window(title="Data", class_name="Static")
|
| GroupBox - 'Options' (L1075, T350, R1746, B541)
| ['Options', 'OptionsGroupBox', 'GroupBox', 'GroupBox0', 'GroupBox1']
| child_window(title="Options", class_name="Button")
|
| Static - 'Original format' (L1093, T376, R1183, B392)
| ['Static5', 'Original format', 'Original formatStatic']
| child_window(title="Original format", class_name="Static")
|
| Static - 'Encoding' (L1450, T378, R1506, B394)
| ['Static6', 'Encoding', 'EncodingStatic']
| child_window(title="Encoding", class_name="Static")
|
| Static - 'Title' (L1093, T438, R1119, B454)
| ['Static7', 'TitleStatic', 'Title']
| child_window(title="Title", class_name="Static")
|
| Static - 'Description\n( Can be viewed in MDict by lookup ':About' )' (L1093, T471, R1247, B534)
| ['Static8', "Description\n( Can be viewed in MDict by lookup ':About' )", "Description\n( Can be viewed in MDict by lookup ':About' )Static"]
| child_window(title="Description\n( Can be viewed in MDict by lookup ':About' )", class_name="Static")
|
| GroupBox - 'Advance' (L1074, T545, R1744, B604)
| ['AdvanceGroupBox', 'GroupBox2', 'Advance']
| child_window(title="Advance", class_name="Button")
|
| Static - 'Index block size(K)' (L1325, T568, R1440, B591)
| ['Static9', 'Index block size(K)', 'Index block size(K)Static']
| child_window(title="Index block size(K)", class_name="Static")
|
| Static - 'Record block size(K)' (L1554, T568, R1680, B591)
| ['Static10', 'Record block size(K)', 'Record block size(K)Static']
| child_window(title="Record block size(K)", class_name="Static")
|
| GroupBox - 'Status' (L1075, T673, R1743, B877)
| ['StatusGroupBox', 'Status', 'GroupBox3']
| child_window(title="Status", class_name="Button")
|
| GroupBox - 'Encrypt' (L1075, T610, R1743, B668)
| ['Encrypt', 'EncryptGroupBox', 'GroupBox4']
| child_window(title="Encrypt", class_name="Button")
|
| Static - 'Encryption Key' (L1089, T636, R1182, B652)
| ['Static11', 'Encryption KeyStatic', 'Encryption Key']
| child_window(title="Encryption Key", class_name="Static")
|
| Static - 'User identified by' (L1415, T636, R1534, B659)
| ['Static12', 'User identified byStatic', 'User identified by']
| child_window(title="User identified by", class_name="Static")
'''
2.pywinauto - PyQt5_Window
from pywinauto.application import Application
##### path:
app = Application().connect(path="PyQt5_Window")
#<class 'pywinauto.application.Application'>
dlg = app.window()
#<class 'pywinauto.application.WindowSpecification'>
dlg.print_control_identifiers()
'''
#####无法检测到子类实例,说明UI属于自绘,不是标准UI #####
Qt5QWindowIcon - '单词复读机' (L551, T177, R1369, B824)
['单词复读机', '单词复读机Qt5QWindowIcon', 'Qt5QWindowIcon']
child_window(title="单词复读机", class_name="Qt5QWindowIcon")
'''
3.pywinauto - Aboboo - 子窗口
from pywinauto.application import Application
##### process:
#app = Application().connect(title_re="MdxBuilder", class_name="#32770")
#app = pywinauto.application.Application().connect(title_re="MdxBuilder", class_name="Dialog")
#32770 (Dialog)
#app = Application().connect(process=2341)
##### handle:
#app = Application().connect(handle=0x010f0c)
##### path:
app = Application().connect(path="E:\\BACKUP\\Aboboo\\Aboboo.Portable.2.9.5\\aboboo.exe")
'''
<class 'pywinauto.application.Application'>
| top_window(self)
| Return WindowSpecification for a current top window of the application
| window(self, **kwargs)
| Return a window of the application
|
| You can specify the same parameters as findwindows.find_windows.
| It will add the process parameter to ensure that the window is from
| the current process.
|
| See :py:func:`pywinauto.findwindows.find_elements` for the full parameters description.
|
| window_ = window(self, **kwargs)
|
| windows(self, **kwargs)
| Return a list of wrapped top level windows of the application
'''
# 在Aboboo中打开子窗口(显示在最前端):操作>编辑句子
sentences_editor = app.top_window() # 最前端窗口
#sentences_editor.print_control_identifiers()
sentences_editor['Edit2'].set_text("第1个输入框, 原文框")
sentences_editor['Button7'].click()
#['Button7', '下一句[F3]', '下一句[F3]Button']
'''
Control Identifiers:
Edit - '' (L634, T183, R1707, B1027)
['Edit', '自动保存编辑内容Edit', 'Edit0', 'Edit1']
child_window(class_name="TfEditSent")
|
| TRzPanel - '' (L634, T183, R1707, B1027)
| ['TRzPanel', '自动保存编辑内容TRzPanel', 'TRzPanel0', 'TRzPanel1']
| child_window(class_name="TRzPanel")
| |
| | StatusBar - '' (L636, T1000, R1704, B1024)
| | ['自动保存编辑内容StatusBar', 'StatusBar']
| | child_window(class_name="TRzStatusBar")
| |
| | TRzPanel - '' (L1354, T259, R1688, B502)
| | ['', 'TRzPanel2', '0', '1']
| | child_window(class_name="TRzPanel")
| | |
| | | TVideoWindow - '' (L1356, T261, R1685, B499)
| | | ['2', 'TVideoWindow']
| | | child_window(class_name="TVideoWindow")
| | | |
| | | | ListBox - '' (L1356, T261, R1356, B486)
| | | | ['3', 'ListBox', 'ListBox0', 'ListBox1']
| | | | child_window(class_name="TRzListBox")
| | |
| | | ListBox - '' (L1356, T261, R1356, B486)
| | | ['3', 'ListBox', 'ListBox0', 'ListBox1']
| | | child_window(class_name="TRzListBox")
| |
| | TVideoWindow - '' (L1356, T261, R1685, B499)
| | ['2', 'TVideoWindow']
| | child_window(class_name="TVideoWindow")
| | |
| | | ListBox - '' (L1356, T261, R1356, B486)
| | | ['3', 'ListBox', 'ListBox0', 'ListBox1']
| | | child_window(class_name="TRzListBox")
| |
| | ListBox - '' (L1356, T261, R1356, B486)
| | ['3', 'ListBox', 'ListBox0', 'ListBox1']
| | child_window(class_name="TRzListBox")
| |
| | TRzPanel - '2 / 47' (L644, T880, R763, B909)
| | ['2 / 47TRzPanel', 'TRzPanel3', '2 / 47']
| | child_window(title="2 / 47", class_name="TRzPanel")
| |
| | Edit - '' (L770, T549, R1681, B702)
| | ['4', 'Edit2']
| | child_window(class_name="TMemo")
| |
| | ListBox - '' (L644, T260, R763, B880)
| | ['5', 'ListBox2']
| | child_window(class_name="TRzListBox")
| |
| | THtmlViewer - '' (L770, T804, R1681, B908)
| | ['6', 'THtmlViewer']
| | child_window(class_name="THtmlViewer")
| | |
| | | TPaintPanel - '' (L773, T806, R1684, B905)
| | | ['7', 'TPaintPanel']
| | | child_window(class_name="TPaintPanel")
| | |
| | | Static - '' (L770, T804, R1681, B908)
| | | ['8', 'Static']
| | | child_window(class_name="TPanel")
| |
| | TPaintPanel - '' (L773, T806, R1684, B905)
| | ['7', 'TPaintPanel']
| | child_window(class_name="TPaintPanel")
| |
| | Static - '' (L770, T804, R1681, B908)
| | ['8', 'Static']
| | child_window(class_name="TPanel")
| |
| | Edit - '第1个输入框, 原文框' (L770, T261, R1681, B361)
| | ['9', 'Edit3']
| | child_window(title="第1个输入框, 原文框", class_name="TMemo")
| |
| | Edit - '' (L770, T738, R1681, B768)
| | ['10', 'Edit4']
| | child_window(class_name="TRzEdit")
| |
| | Edit - '' (L770, T400, R1681, B500)
| | ['11', 'Edit5']
| | child_window(class_name="TMemo")
| |
| | Button - '循环朗读' (L968, T928, R1067, B956)
| | ['循环朗读Button', 'Button', '循环朗读', 'Button0', 'Button1']
| | child_window(title="循环朗读", class_name="TRzCheckBox")
| |
| | Button - '自动保存编辑内容' (L643, T928, R817, B956)
| | ['自动保存编辑内容Button', '自动保存编辑内容', 'Button2']
| | child_window(title="自动保存编辑内容", class_name="TRzCheckBox")
| |
| | Button - '自动朗读句子' (L824, T928, R960, B956)
| | ['Button3', '自动朗读句子Button', '自动朗读句子']
| | child_window(title="自动朗读句子", class_name="TRzCheckBox")
| |
| | Button - '保存[Ctrl+S]' (L1439, T921, R1579, B965)
| | ['Button4', '保存[Ctrl+S]Button', '保存[Ctrl+S]']
| | child_window(title="保存[Ctrl+S]", class_name="TRzButton")
| |
| | Button - '上一句[F2]' (L1204, T921, R1318, B965)
| | ['Button5', '上一句[F2]', '上一句[F2]Button']
| | child_window(title="上一句[F2]", class_name="TRzButton")
| |
| | Button - '停 止[F1]' (L1085, T921, R1199, B965)
| | ['停 止[F1]', 'Button6', '停 止[F1]Button']
| | child_window(title="停 止[F1]", class_name="TRzButton")
| |
| | Button - '下一句[F3]' (L1321, T921, R1435, B965)
| | ['Button7', '下一句[F3]', '下一句[F3]Button']
| | child_window(title="下一句[F3]", class_name="TRzButton")
| |
| | Button - '关 闭' (L1584, T921, R1694, B965)
| | ['Button8', '关 闭', '关 闭Button']
| | child_window(title="关 闭", class_name="TRzButton")
| |
| | TRzPanel - '编辑句子' (L636, T185, R1704, B221)
| | ['TRzPanel4', '编辑句子', '编辑句子TRzPanel']
| | child_window(title="编辑句子", class_name="TRzPanel")
| | |
| | | Button - '' (L1670, T186, R1701, B210)
| | | ['12', 'Button9']
| | | child_window(class_name="TPNGHoverButton")
| |
| | Button - '' (L1670, T186, R1701, B210)
| | ['12', 'Button9']
| | child_window(class_name="TPNGHoverButton")
|
| StatusBar - '' (L636, T1000, R1704, B1024)
| ['自动保存编辑内容StatusBar', 'StatusBar']
| child_window(class_name="TRzStatusBar")
|
| TRzPanel - '' (L1354, T259, R1688, B502)
| ['', 'TRzPanel2', '0', '1']
| child_window(class_name="TRzPanel")
| |
| | TVideoWindow - '' (L1356, T261, R1685, B499)
| | ['2', 'TVideoWindow']
| | child_window(class_name="TVideoWindow")
| | |
| | | ListBox - '' (L1356, T261, R1356, B486)
| | | ['3', 'ListBox', 'ListBox0', 'ListBox1']
| | | child_window(class_name="TRzListBox")
| |
| | ListBox - '' (L1356, T261, R1356, B486)
| | ['3', 'ListBox', 'ListBox0', 'ListBox1']
| | child_window(class_name="TRzListBox")
|
| TVideoWindow - '' (L1356, T261, R1685, B499)
| ['2', 'TVideoWindow']
| child_window(class_name="TVideoWindow")
| |
| | ListBox - '' (L1356, T261, R1356, B486)
| | ['3', 'ListBox', 'ListBox0', 'ListBox1']
| | child_window(class_name="TRzListBox")
|
| ListBox - '' (L1356, T261, R1356, B486)
| ['3', 'ListBox', 'ListBox0', 'ListBox1']
| child_window(class_name="TRzListBox")
|
| TRzPanel - '2 / 47' (L644, T880, R763, B909)
| ['2 / 47TRzPanel', 'TRzPanel3', '2 / 47']
| child_window(title="2 / 47", class_name="TRzPanel")
|
| Edit - '' (L770, T549, R1681, B702)
| ['4', 'Edit2']
| child_window(class_name="TMemo")
|
| ListBox - '' (L644, T260, R763, B880)
| ['5', 'ListBox2']
| child_window(class_name="TRzListBox")
|
| THtmlViewer - '' (L770, T804, R1681, B908)
| ['6', 'THtmlViewer']
| child_window(class_name="THtmlViewer")
| |
| | TPaintPanel - '' (L773, T806, R1684, B905)
| | ['7', 'TPaintPanel']
| | child_window(class_name="TPaintPanel")
| |
| | Static - '' (L770, T804, R1681, B908)
| | ['8', 'Static']
| | child_window(class_name="TPanel")
|
| TPaintPanel - '' (L773, T806, R1684, B905)
| ['7', 'TPaintPanel']
| child_window(class_name="TPaintPanel")
|
| Static - '' (L770, T804, R1681, B908)
| ['8', 'Static']
| child_window(class_name="TPanel")
|
| Edit - '第1个输入框, 原文框' (L770, T261, R1681, B361)
| ['9', 'Edit3']
| child_window(title="第1个输入框, 原文框", class_name="TMemo")
|
| Edit - '' (L770, T738, R1681, B768)
| ['10', 'Edit4']
| child_window(class_name="TRzEdit")
|
| Edit - '' (L770, T400, R1681, B500)
| ['11', 'Edit5']
| child_window(class_name="TMemo")
|
| Button - '循环朗读' (L968, T928, R1067, B956)
| ['循环朗读Button', 'Button', '循环朗读', 'Button0', 'Button1']
| child_window(title="循环朗读", class_name="TRzCheckBox")
|
| Button - '自动保存编辑内容' (L643, T928, R817, B956)
| ['自动保存编辑内容Button', '自动保存编辑内容', 'Button2']
| child_window(title="自动保存编辑内容", class_name="TRzCheckBox")
|
| Button - '自动朗读句子' (L824, T928, R960, B956)
| ['Button3', '自动朗读句子Button', '自动朗读句子']
| child_window(title="自动朗读句子", class_name="TRzCheckBox")
|
| Button - '保存[Ctrl+S]' (L1439, T921, R1579, B965)
| ['Button4', '保存[Ctrl+S]Button', '保存[Ctrl+S]']
| child_window(title="保存[Ctrl+S]", class_name="TRzButton")
|
| Button - '上一句[F2]' (L1204, T921, R1318, B965)
| ['Button5', '上一句[F2]', '上一句[F2]Button']
| child_window(title="上一句[F2]", class_name="TRzButton")
|
| Button - '停 止[F1]' (L1085, T921, R1199, B965)
| ['停 止[F1]', 'Button6', '停 止[F1]Button']
| child_window(title="停 止[F1]", class_name="TRzButton")
|
| Button - '下一句[F3]' (L1321, T921, R1435, B965)
| ['Button7', '下一句[F3]', '下一句[F3]Button']
| child_window(title="下一句[F3]", class_name="TRzButton")
|
| Button - '关 闭' (L1584, T921, R1694, B965)
| ['Button8', '关 闭', '关 闭Button']
| child_window(title="关 闭", class_name="TRzButton")
|
| TRzPanel - '编辑句子' (L636, T185, R1704, B221)
| ['TRzPanel4', '编辑句子', '编辑句子TRzPanel']
| child_window(title="编辑句子", class_name="TRzPanel")
| |
| | Button - '' (L1670, T186, R1701, B210)
| | ['12', 'Button9']
| | child_window(class_name="TPNGHoverButton")
|
| Button - '' (L1670, T186, R1701, B210)
| ['12', 'Button9']
| child_window(class_name="TPNGHoverButton")
'''
标签:控制,name,title,pywinauto,Button,child,window,自动化,class 来源: https://blog.csdn.net/ericatardicaca/article/details/94355693