我想使用pywinauto进行一些自动化,并且我在阅读DataGridView表时陷入困境。如何将其转换为可读表?我需要在表格中查看实际数据。表中的列是动态的,您可以添加或删除所需的列。据我所知,我需要使用ListViewWrapper转换ir,但我无法获取表格的元素。控件标识符:
app = Application(backend='uia').connect(title_re=app_regex)
dgv = app.top_window().DataGridView
dgv.print_control_identifiers()
Table - 'DataGridView' (L198, T191, R1366, B621)
['DataGridViewTable', 'Table', 'DataGridView']
child_window(title="DataGridView", auto_id="dgvBrowser", control_type="Table")
|
| ScrollBar - 'Vertical Scroll Bar' (L1348, T192, R1365, B620)
| ['ScrollBar', 'Vertical Scroll BarScrollBar', 'Vertical Scroll Bar']
| child_window(title="Vertical Scroll Bar", auto_id="4261242", control_type="ScrollBar")
| |
| | Button - 'Line up' (L1348, T192, R1365, B209)
| | ['Button', 'Line up', 'Line upButton', 'Button0', 'Button1']
| | child_window(title="Line up", control_type="Button")
| |
| | Thumb - 'Position' (L1348, T209, R1365, B590)
| | ['Position', 'PositionThumb', 'Thumb']
| | child_window(title="Position", control_type="Thumb")
| |
| | Button - 'Page down' (L1348, T590, R1365, B603)
| | ['Button2', 'Page down', 'Page downButton']
| | child_window(title="Page down", control_type="Button")
| |
| | Button - 'Line down' (L1348, T603, R1365, B620)
| | ['Button3', 'Line down', 'Line downButton']
| | child_window(title="Line down", control_type="Button")
|
| Custom - 'Top Row' (L198, T191, R1348, B213)
| ['Custom', 'Top RowCustom', 'Top Row', 'Custom0', 'Custom1']
| child_window(title="Top Row", control_type="Custom")
| |
| | Header - '' (L199, T191, R239, B213)
| | ['', 'Header', '0', '1', 'Header0', 'Header1']
| |
| | Header - '' (L239, T191, R264, B213)
| | ['2', 'Header2']
| |
| | Header - 'Data' (L264, T191, R352, B213)
| | ['DataHeader', 'Header3', 'Data']
| | child_window(title="Data", control_type="Header")
| |
| | Header - 'Technikas' (L352, T191, R484, B213)
| | ['TechnikasHeader', 'Technikas', 'Header4']
| | child_window(title="Technikas", control_type="Header")
| |
| | Header - 'Paskyros numeris' (L484, T191, R638, B213)
| | ['Paskyros numerisHeader', 'Header5', 'Paskyros numeris']
| | child_window(title="Paskyros numeris", control_type="Header")
| |
| | Header - 'Objektas-Adresas' (L638, T191, R762, B213)
| | ['Objektas-Adresas', 'Objektas-AdresasHeader', 'Header6']
| | child_window(title="Objektas-Adresas", control_type="Header")
| |
| | Header - 'Klientas' (L762, T191, R866, B213)
| | ['Klientas', 'Header7', 'KlientasHeader']
| | child_window(title="Klientas", control_type="Header")
| |
| | Header - 'Stadija' (L866, T191, R997, B213)
| | ['StadijaHeader', 'Header8', 'Stadija']
| | child_window(title="Stadija", control_type="Header")
| |
| | Header - 'Darbu vykdytojas' (L997, T191, R1147, B213)
| | ['Darbu vykdytojasHeader', 'Darbu vykdytojas', 'Header9']
| | child_window(title="Darbu vykdytojas", control_type="Header")
| |
| | Header - 'Projektas' (L1147, T191, R1348, B213)
| | ['ProjektasHeader', 'Header10', 'Projektas']
| | child_window(title="Projektas", control_type="Header")
|
| Custom - 'Row 0' (L199, T213, R1348, B234)
| ['Custom2', 'Row 0Custom', 'Row 0']
| child_window(title="Row 0", control_type="Custom")
| |
| | Custom - ' Row 0' (L199, T213, R239, B234)
| | ['Custom3', ' Row 0', ' Row 0Custom', ' Row 00', ' Row 01', ' Row 0Custom0', ' Row 0Custom1']
| | child_window(title=" Row 0", control_type="Custom")
| |
| | Custom - ' Row 0' (L239, T213, R264, B234)
| | ['Custom4', ' Row 02', ' Row 0Custom2']
| | child_window(title=" Row 0", control_type="Custom")
| |
| | Custom - 'Data Row 0' (L264, T213, R352, B234)
| | ['Custom5', 'Data Row 0Custom', 'Data Row 0']
| | child_window(title="Data Row 0", control_type="Custom")
| |
| | Custom - 'Technikas Row 0' (L352, T213, R484, B234)
| | ['Custom6', 'Technikas Row 0', 'Technikas Row 0Custom']
| | child_window(title="Technikas Row 0", control_type="Custom")
| |
| | Custom - 'Paskyros numeris Row 0' (L484, T213, R638, B234)
| | ['Custom7', 'Paskyros numeris Row 0Custom', 'Paskyros numeris Row 0']
| | child_window(title="Paskyros numeris Row 0", control_type="Custom")
| |
| | Custom - 'Objektas-Adresas Row 0' (L638, T213, R762, B234)
| | ['Custom8', 'Objektas-Adresas Row 0', 'Objektas-Adresas Row 0Custom']
| | child_window(title="Objektas-Adresas Row 0", control_type="Custom")
| |
| | Custom - 'Klientas Row 0' (L762, T213, R866, B234)
| | ['Custom9', 'Klientas Row 0Custom', 'Klientas Row 0']
| | child_window(title="Klientas Row 0", control_type="Custom")
| |
| | Custom - 'Stadija Row 0' (L866, T213, R997, B234)
| | ['Custom10', 'Stadija Row 0', 'Stadija Row 0Custom']
| | child_window(title="Stadija Row 0", control_type="Custom")
| |
| | Custom - 'Darbu vykdytojas Row 0' (L997, T213, R1147, B234)
| | ['Custom11', 'Darbu vykdytojas Row 0', 'Darbu vykdytojas Row 0Custom']
| | child_window(title="Darbu vykdytojas Row 0", control_type="Custom")
| |
| | Custom - 'Projektas Row 0' (L1147, T213, R1348, B234)
| | ['Custom12', 'Projektas Row 0', 'Projektas Row 0Custom']
| | child_window(title="Projektas Row 0", control_type="Custom")
|
| Custom - 'Row 1' (L199, T234, R1348, B255)
| ['Custom13', 'Row 1', 'Row 1Custom']
| child_window(title="Row 1", control_type="Custom")
| |
| | Custom - ' Row 1' (L199, T234, R239, B255)
| | ['Custom14', ' Row 1Custom', ' Row 1', ' Row 1Custom0', ' Row 1Custom1', ' Row 10', ' Row 11', ' Row 100', ' Row 101', ' Row 110', ' Row 111']
| | child_window(title=" Row 1", control_type="Custom")
| |
| | Custom - ' Row 1' (L239, T234, R264, B255)
| | ['Custom15', ' Row 1Custom2', ' Row 12', ' Row 120', ' Row 121']
| | child_window(title=" Row 1", control_type="Custom")
| |
| | Custom - 'Data Row 1' (L264, T234, R352, B255)
| | ['Custom16', 'Data Row 1Custom', 'Data Row 1']
| | child_window(title="Data Row 1", control_type="Custom")
| |
| | Custom - 'Technikas Row 1' (L352, T234, R484, B255)
| | ['Custom17', 'Technikas Row 1Custom', 'Technikas Row 1']
| | child_window(title="Technikas Row 1", control_type="Custom")
| |
| | Custom - 'Paskyros numeris Row 1' (L484, T234, R638, B255)
| | ['Custom18', 'Paskyros numeris Row 1', 'Paskyros numeris Row 1Custom']
| | child_window(title="Paskyros numeris Row 1", control_type="Custom")
由于
答案 0 :(得分:0)
你可能不喜欢这个答案,但目前的情况对你的任务不利。
如果您无法访问应用源代码,则无法使用pywinauto获取文本。
但如果有,则需要为此控件类型实现所谓的服务器提供程序(在MSDN上的UI Automation API文档中进行了描述)。虽然我从未尝试过这种方式。
另一种理论上可行的方法应该使用托管DLL注入来访问自定义.NET控件的内部属性。我知道TestComplete,Squish和UFT都是这样使用的。但它们都非常昂贵。从未听说过使用这种方法的任何开源工具。
P.S。屏幕文本识别在理论上也是可能的方式,但是工具还不够成熟,无法可靠地识别它。