使用pywinauto进行python gui自动化,查找元素

时间:2018-11-02 18:44:36

标签: python pywinauto python-3.7

我试图通过Python运行坐在Toon Boom Storyboard Pro中工具栏中的一些脚本。

这是我到目前为止所拥有的:

import subprocess import os import pywinauto import time import sys

appPath = os.environ['PROGRAMFILES(x86)'] + r'\Toon Boom Animation\Toon Boom Storyboard Pro 6\win64\bin\StoryboardPro.exe'
filePath = r'C:\Users\kjain\Desktop\!exports\TEST1_101_SQ01_v07\TEST1_101_SQ01_v29.sboard' 
sp = subprocess.Popen(f'"{appPath}" "{filePath}"')
app = pywinauto.application.Application(backend="uia")
time.sleep(8)
app = app.connect(path = appPath);
try:
    menu = app['Toon Boom Storyboard Pro 6 Project: TEST1_101_SQ01_v07']
    menu.menu_select('File->Open')
except:
    print(sys.exc_info())

我得到:

(<class 'AttributeError'>, AttributeError(), <traceback object at 0x00000034A076BC08>)

运行menu.print_control_identifiers(),我被截断了:

Control Identifiers:

Dialog - 'Toon Boom Storyboard Pro 6 Project: TEST1_101_SQ01_v07'    (L-8, T-8, R1608, B1168)
['Toon Boom Storyboard Pro 6 Project: TEST1_101_SQ01_v07', 'Dialog', 'Toon Boom Storyboard Pro 6 Project: TEST1_101_SQ01_v07Dialog']
child_window(title="Toon Boom Storyboard Pro 6 Project: TEST1_101_SQ01_v07", control_type="Window")
   |
   | Pane - ''    (L1302, T46, R1547, B79)
   | ['Pane', '', '0', '1', 'Pane0', 'Pane1']
   |    |
   |    | Custom - ''    (L1536, T46, R1548, B79)
   |    | ['2', 'Custom', 'Custom0', 'Custom1']
   |    |
   |    | Custom - ''    (L1310, T46, R1343, B79)
   |    | ['3', 'Custom2']
   |    |
   |    | Custom - ''    (L1343, T46, R1384, B79)
   |    | ['4', 'Custom3']
   |    |
   |    | Custom - ''    (L1384, T46, R1425, B79)
   |    | ['5', 'Custom4']
   |    |
   |    | Custom - ''    (L1425, T46, R1509, B79)
   |    | ['6', 'Custom5']
   |    |    |
   |    |    | Custom - ''    (L1427, T52, R1507, B72)
   |    |    | ['7', 'Custom6']
   |
   | Pane - ''    (L1547, T46, R1600, B79)
   | ['Pane2', '8']
   |    |
   |    | Custom - ''    (L1589, T46, R1601, B79)
   |    | ['9', 'Custom7']
   |    |
   |    | Custom - ''    (L1555, T46, R1588, B79)
   |    | ['10', 'Custom8']
   |
   | Pane - ''    (L1022, T46, R1096, B79)
   | ['Pane3', '11']
   |    |
   |    | Custom - ''    (L1030, T46, R1063, B79)
   |    | ['12', 'Custom9']
   |    |
   |    | Custom - ''    (L1063, T46, R1096, B79)
   |    | ['13', 'Custom10']
   |
   | Pane - ''    (L0, T616, R33, B1160)
   | ['Pane4', '14']
   |    |
   |    | Custom - ''    (L0, T624, R33, B657)
   |    | ['15', 'Custom11']
   |    |
   |    | Custom - ''    (L0, T657, R33, B690)
   |    | ['16', 'Custom12']
   |    |
   |    | Custom - ''    (L0, T690, R33, B723)
   |    | ['17', 'Custom13']
   |    |
   |    | Custom - ''    (L0, T723, R33, B756)
   |    | ['18', 'Custom14']
   |    |
   |    | Custom - ''    (L0, T756, R33, B789)
   |    | ['19', 'Custom15']
   |
   | Pane - ''    (L684, T46, R1022, B79)
   | ['Pane5', '20']
   |    |
   |    | Custom - ''    (L692, T46, R725, B79)
   |    | ['21', 'Custom16']
   |    |
   |    | Custom - ''    (L725, T46, R758, B79)
   |    | ['22', 'Custom17']
   |    |
   |    | Custom - ''    (L758, T46, R791, B79)
   |    | ['23', 'Custom18']
   |    |
   |    | Custom - ''    (L791, T46, R824, B79)
   |    | ['24', 'Custom19']
   |    |
   |    | Custom - ''    (L824, T46, R857, B79)
   |    | ['25', 'Custom20']
   |    |
   |    | Custom - ''    (L857, T46, R890, B79)
   |    | ['26', 'Custom21']
   |    |
   |    | Custom - ''    (L890, T46, R923, B79)
   |    | ['27', 'Custom22']
   |    |
   |    | Custom - ''    (L923, T46, R956, B79)
   |    | ['28', 'Custom23']
   |    |
   |    | Custom - ''    (L956, T46, R989, B79)
   |    | ['29', 'Custom24']
   |    |
   |    | Custom - ''    (L989, T46, R1022, B79)
   |    | ['30', 'Custom25']
   |
   | Pane - ''    (L0, T79, R33, B616)
   | ['Pane6', '31']
   |    |
   |    | Custom - ''    (L0, T87, R33, B120)
   |    | ['32', 'Custom26']
   |    |
   |    | Custom - ''    (L0, T120, R33, B153)
   |    | ['33', 'Custom27']
   |    |
   |    | Custom - ''    (L0, T153, R33, B186)
   |    | ['34', 'Custom28']
   |    |
   |    | Custom - ''    (L0, T186, R33, B219)
   |    | ['35', 'Custom29']
   |    |
   |    | Custom - ''    (L0, T219, R33, B252)
   |    | ['36', 'Custom30']
   |    |
   |    | Custom - ''    (L0, T252, R33, B285)
   |    | ['37', 'Custom31']
   |    |
   |    | Custom - ''    (L0, T285, R33, B318)
   |    | ['38', 'Custom32']
   |    |
   |    | Custom - ''    (L0, T318, R33, B351)
   |    | ['39', 'Custom33']
   |    |
   |    | Custom - ''    (L0, T351, R33, B384)
   |    | ['40', 'Custom34']
   |    |
   |    | Custom - ''    (L0, T384, R33, B417)
   |    | ['41', 'Custom35']
   |    |
   |    | Custom - ''    (L0, T417, R33, B450)
   |    | ['42', 'Custom36']
   |    |
   |    | Custom - ''    (L0, T450, R33, B451)
   |    | ['43', 'Custom37']
   |    |
   |    | Custom - ''    (L0, T451, R33, B484)
   |    | ['44', 'Custom38']
   |    |
   |    | Custom - ''    (L0, T484, R33, B517)
   |    | ['45', 'Custom39']
   |    |
   |    | Custom - ''    (L0, T517, R33, B550)
   |    | ['46', 'Custom40']
   |    |
   |    | Custom - ''    (L0, T550, R33, B583)
   |    | ['47', 'Custom41']
   |    |
   |    | Custom - ''    (L0, T583, R33, B616)
   |    | ['48', 'Custom42']
   |
   | Pane - ''    (L1096, T46, R1302, B79)
   | ['Pane7', '49']
   |    |
   |    | Custom - ''    (L1104, T46, R1137, B79)
   |    | ['50', 'Custom43']
   |    |
   |    | Custom - ''    (L1137, T46, R1170, B79)
   |    | ['51', 'Custom44']
   |    |
   |    | Custom - ''    (L1170, T46, R1203, B79)
   |    | ['52', 'Custom45']
   |    |
   |    | Custom - ''    (L1203, T46, R1236, B79)
   |    | ['53', 'Custom46']
   |    |
   |    | Custom - ''    (L1236, T46, R1269, B79)
   |    | ['54', 'Custom47']
   |    |
   |    | Custom - ''    (L1269, T46, R1302, B79)
   |    | ['55', 'Custom48']
   |
   | Pane - ''    (L33, T79, R66, B1160)
   | ['Pane8', '56']
   |    |
   |    | Custom - ''    (L33, T87, R66, B120)
   |    | ['57', 'Custom49']
   |    |
   |    | Custom - ''    (L33, T120, R66, B153)
   |    | ['58', 'Custom50']
   |    |
   |    | Custom - ''    (L33, T153, R66, B154)
   |    | ['59', 'Custom51']
   |    |
   |    | Custom - ''    (L33, T154, R66, B187)
   |    | ['60', 'Custom52']
   |    |
   |    | Custom - ''    (L33, T187, R66, B220)
   |    | ['61', 'Custom53']
   |    |
   |    | Custom - ''    (L33, T220, R66, B253)
   |    | ['62', 'Custom54']
   |    |
   |    | Custom - ''    (L33, T253, R66, B286)
   |    | ['63', 'Custom55']
   |    |
   |    | Custom - ''    (L33, T286, R66, B319)
   |    | ['64', 'Custom56']
   |    |
   |    | Custom - ''    (L33, T319, R66, B352)
   |    | ['65', 'Custom57']
   |    |
   |    | Custom - ''    (L33, T352, R66, B385)
   |    | ['66', 'Custom58']
   |    |
   |    | Custom - ''    (L33, T385, R66, B418)
   |    | ['67', 'Custom59']
   |    |
   |    | Custom - ''    (L33, T418, R66, B451)
   |    | ['68', 'Custom60']
   |    |
   |    | Custom - ''    (L33, T451, R66, B484)
   |    | ['69', 'Custom61']
   |    |
   |    | Custom - ''    (L33, T484, R66, B517)
   |    | ['70', 'Custom62']
   |    |
   |    | Custom - ''    (L33, T517, R66, B550)
   |    | ['71', 'Custom63']
   |    |
   |    | Custom - ''    (L33, T550, R66, B583)
   |    | ['72', 'Custom64']
   |    |
   |    | Custom - ''    (L33, T583, R66, B616)
   |    | ['73', 'Custom65']
   |
   | Pane - ''    (L346, T46, R684, B79)
   | ['Pane9', '74']
   |    |
   |    | Custom - ''    (L354, T46, R387, B79)
   |    | ['75', 'Custom66']
   |    |
   |    | Custom - ''    (L387, T46, R420, B79)
   |    | ['76', 'Custom67']
   |    |
   |    | Custom - ''    (L420, T46, R453, B79)
   |    | ['77', 'Custom68']
   |    |
   |    | Custom - ''    (L453, T46, R486, B79)
   |    | ['78', 'Custom69']
   |    |
   |    | Custom - ''    (L486, T46, R519, B79)
   |    | ['79', 'Custom70']
   |    |
   |    | Custom - ''    (L519, T46, R552, B79)
   |    | ['80', 'Custom71']
   |    |
   |    | Custom - ''    (L552, T46, R585, B79)
   |    | ['81', 'Custom72']
   |    |
   |    | Custom - ''    (L585, T46, R618, B79)
   |    | ['82', 'Custom73']
   |    |
   |    | Custom - ''    (L0, T0, R0, B0)
   |    | ['83', 'Custom74']
   |    |
   |    | Custom - ''    (L618, T46, R651, B79)
   |    | ['84', 'Custom75']
   |    |
   |    | Custom - ''    (L651, T46, R684, B79)
   |    | ['85', 'Custom76']
   |
   | Pane - ''    (L140, T46, R346, B79)
   | ['Pane10', '86']
   |    |
   |    | Custom - ''    (L148, T46, R181, B79)
   |    | ['87', 'Custom77']
   |    |
   |    | Custom - ''    (L181, T46, R214, B79)
   |    | ['88', 'Custom78']
   |    |
   |    | Custom - ''    (L214, T46, R247, B79)
   |    | ['89', 'Custom79']
   |    |
   |    | Custom - ''    (L247, T46, R280, B79)
   |    | ['90', 'Custom80']
   |    |
   |    | Custom - ''    (L0, T0, R0, B0)
   |    | ['83', 'Custom74']
   |    |
   |    | Custom - ''    (L280, T46, R313, B79)
   |    | ['92', 'Custom82']
   |    |
   |    | Custom - ''    (L313, T46, R346, B79)
   |    | ['93', 'Custom83']
   |
   | Pane - ''    (L0, T46, R140, B79)
   | ['Pane11', '94']
   |    |
   |    | Custom - ''    (L8, T46, R41, B79)
   |    | ['95', 'Custom84']
   |    |
   |    | Custom - ''    (L41, T46, R74, B79)
   |    | ['96', 'Custom85']
   |    |
   |    | Custom - ''    (L74, T46, R107, B79)
   |    | ['97', 'Custom86']
   |    |
   |    | Custom - ''    (L107, T46, R140, B79)
   |    | ['98', 'Custom87']
   |
   | Pane - ''    (L0, T23, R1600, B46)
   | ['Pane12', '99']
   |
   | Pane - ''    (L66, T79, R1600, B1160)
   | ['Pane13', '100']
   |    |
   |    | Pane - ''    (L66, T79, R1600, B1160)
   |    | ['Pane14', '101']
   |    |    |
   |    |    | Pane - ''    (L66, T953, R1600, B963)
   |    |    | ['Pane15', '102']
   |    |    |
   |    |    | Pane - ''    (L66, T963, R1600, B1160)
   |    |    | ['Pane16', '103']
   |    |    |    |
   |    |    |    | Custom - ''    (L1434, T966, R1561, B985)
   |    |    |    | ['104', 'Custom88']
   |    |    |    |
   |    |    |    | Custom - ''    (L1563, T968, R1579, B984)
   |    |    |    | ['105', 'Custom89']
   |    |    |    |
   |    |    |    | Custom - ''    (L1579, T968, R1595, B984)
   |    |    |    | ['106', 'Custom90']
   |    |    |    |
   |    |    |    | Custom - ''    (L69, T988, R1597, B1157)
   |    |    |    | ['107', 'Custom91']
   |    |    |    |    |
   |    |    |    |    | Custom - ''    (L69, T988, R1597, B1157)
   |    |    |    |    | ['107', 'Custom91']
   |    |    |    |    |    |
   |    |    |    |    |    | Custom - ''    (L69, T988, R1597, B1157)
   |    |    |    |    |    | ['107', 'Custom91']
   |    |    |    |    |    |    |
   |    |    |    |    |    |    | Custom - ''    (L69, T988, R1597, B1157)
   |    |    |    |    |    |    | ['110', 'Custom94']
   |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    | Custom - ''    (L1581, T988, R1597, B1131)
   |    |    |    |    |    |    |    | ['111', 'Custom95']
   |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    | Custom - ''    (L189, T1131, R1581, B1157)
   |    |    |    |    |    |    |    | ['112', 'Custom96']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L189, T1131, R192, B1157)
   |    |    |    |    |    |    |    |    | ['113', 'Custom97']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L194, T1131, R220, B1157)
   |    |    |    |    |    |    |    |    | ['114', 'Custom98']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L222, T1133, R312, B1155)
   |    |    |    |    |    |    |    |    | ['115', 'Custom99']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L314, T1136, R1581, B1152)
   |    |    |    |    |    |    |    |    | ['116', 'Custom100']
   |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    | Custom - ''    (L0, T0, R0, B0)
   |    |    |    |    |    |    |    | ['83', 'Custom74']
   |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    | Custom - ''    (L189, T988, R1581, B1131)
   |    |    |    |    |    |    |    | ['118', 'Custom102']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L190, T989, R1580, B1130)
   |    |    |    |    |    |    |    |    | ['119', 'Custom103']
   |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    | Custom - ''    (L69, T988, R189, B1131)
   |    |    |    |    |    |    |    | ['120', 'Custom104']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L70, T989, R188, B1130)
   |    |    |    |    |    |    |    |    | ['121', 'Custom105']
   |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    | Custom - ''    (L69, T1131, R189, B1157)
   |    |    |    |    |    |    |    | ['122', 'Custom106']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L69, T1131, R95, B1157)
   |    |    |    |    |    |    |    |    | ['123', 'Custom107']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L95, T1131, R121, B1157)
   |    |    |    |    |    |    |    |    | ['124', 'Custom108']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L121, T1131, R147, B1157)
   |    |    |    |    |    |    |    |    | ['125', 'Custom109']
   |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    | Custom - ''    (L163, T1131, R189, B1157)
   |    |    |    |    |    |    |    |    | ['126', 'Custom110']
   |    |    |
   |    |    | Pane - ''    (L66, T79, R1600, B953)
   |    |    | ['Pane17', '127']
   |    |    |    |
   |    |    |    | Pane - ''    (L1240, T79, R1250, B953)
   |    |    |    | ['Pane18', '128']
   |    |    |    |
   |    |    |    | Pane - ''    (L66, T79, R1240, B953)
   |    |    |    | ['Pane19', '129']
   |    |    |    |    |
   |    |    |    |    | Pane - ''    (L1219, T85, R1235, B101)
   |    |    |    |    | ['Pane20', '130']
   |    |    |    |    |
   |    |    |    |    | Pane - ''    (L1203, T85, R1219, B101)
   |    |    |    |    | ['Pane21', '131']
   |    |    |    |    |
   |    |    |    |    | Pane - ''    (L69, T106, R1237, B950)
   |    |    |    |    | ['Pane22', '132']
...
   |    |    |    |    |    |    |    |    |    |    |    |
   |    |    |    |    |    |    |    |    |    |    |    | Custom - ''    (L1255, T810, R1595, B820)
   |    |    |    |    |    |    |    |    |    |    |    | ['263', 'Custom227']
   |
   | TitleBar - ''    (L16, T-5, R1600, B23)
   | ['264', 'TitleBar']
   |    |
   |    | Menu - 'System'    (L0, T0, R22, B22)
   |    | ['Menu', 'System', 'SystemMenu', 'System0', 'System1']
   |    | child_window(title="System", auto_id="MenuBar", control_type="MenuBar")
   |    |    |
   |    |    | MenuItem - 'System'    (L0, T0, R22, B22)
   |    |    | ['SystemMenuItem', 'MenuItem', 'System2']
   |    |    | child_window(title="System", control_type="MenuItem")
   |    |
   |    | Button - 'Minimize'    (L1497, T0, R1525, B20)
   |    | ['MinimizeButton', 'Minimize', 'Button', 'Button0', 'Button1']
   |    | child_window(title="Minimize", control_type="Button")
   |    |
   |    | Button - 'Restore'    (L1525, T0, R1551, B20)
   |    | ['Restore', 'RestoreButton', 'Button2']
   |    | child_window(title="Restore", control_type="Button")
   |    |
   |    | Button - 'Close'    (L1551, T0, R1598, B20)
   |    | ['Close', 'CloseButton', 'Button3']
   |    | child_window(title="Close", control_type="Button")

这就是我使用UISpy所获得的,尽管说实话,如果它告诉我任何有用的信息,我不确定如何使用它

这是我尝试运行的自定义脚本工具栏上的脚本

关于如何控制此GUI的任何想法?我什至在任何控件标识符上都没有看到class_names,也没有看到“ Custom”以外的名称。

0 个答案:

没有答案