Pywinauto常用01--print_control_identifiers()
Posted nikeylee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Pywinauto常用01--print_control_identifiers()相关的知识,希望对你有一定的参考价值。
目录
window.print_control_identifiers():
window.print_control_identifiers():
查看该窗口下所有的子窗口的类名、标题、位置、控制类型等信息
window.print_control_identifiers(depth=None, filename=None)
参数depth,filename默认都是None,可以不指定
depth:输出层数控制,可以指定输出的层级,如只输出第一层,depth=1;
filename:直接将结果保存为文件。如果指定文件名,则控台就不会再输出,输出结果都保存在文件中;
代码举例:
1、默认不指定参数,全部输出:
window.print_control_identifiers()
from pywinauto.application import Application
# 通过窗口句柄连接已经启动的记事本程序,记事本的窗口句柄NativeWindowHandle为2564730
handle = 2564730
app = Application(backend='uia').connect(handle=handle)
# 通过窗口title指定待操作窗口
window = app['test001.txt - 记事本']
# 控台输出该窗口下所有的子窗口的类名、标题、位置、控制类型等信息
window.print_control_identifiers()
控台输出信息如下:
Control Identifiers:
Dialog - 'test001.txt - 记事本' (L228, T831, R2015, B1691)
['Dialog', 'test001.txt - 记事本', 'test001.txt - 记事本Dialog']
child_window(title="test001.txt - 记事本", control_type="Window")
|
| Edit - '文本编辑器' (L239, T906, R2004, B1646)
| ['Edit']
| child_window(title="文本编辑器", auto_id="15", control_type="Edit")
| |
| | ScrollBar - '垂直滚动条' (L1978, T906, R2004, B1620)
| | ['垂直滚动条', 'ScrollBar', '垂直滚动条ScrollBar', 'ScrollBar0', 'ScrollBar1']
| | child_window(title="垂直滚动条", auto_id="NonClientVerticalScrollBar", control_type="ScrollBar")
| | |
| | | Button - '上一行' (L1978, T906, R2004, B932)
| | | ['Button', '上一行', '上一行Button', 'Button0', 'Button1']
| | | child_window(title="上一行", auto_id="UpButton", control_type="Button")
| | |
| | | Button - '下一行' (L1978, T1594, R2004, B1620)
| | | ['下一行Button', '下一行', 'Button2']
| | | child_window(title="下一行", auto_id="DownButton", control_type="Button")
| |
| | ScrollBar - '水平滚动条' (L239, T1620, R1978, B1646)
| | ['水平滚动条', 'ScrollBar2', '水平滚动条ScrollBar']
| | child_window(title="水平滚动条", auto_id="NonClientHorizontalScrollBar", control_type="ScrollBar")
| | |
| | | Button - '左移一列' (L239, T1620, R265, B1646)
| | | ['左移一列', '左移一列Button', 'Button3']
| | | child_window(title="左移一列", auto_id="UpButton", control_type="Button")
| | |
| | | Button - '右移一列' (L1952, T1620, R1978, B1646)
| | | ['右移一列Button', '右移一列', 'Button4']
| | | child_window(title="右移一列", auto_id="DownButton", control_type="Button")
| |
| | Thumb - '' (L1978, T1620, R2004, B1646)
| | ['Thumb']
|
| StatusBar - '状态栏' (L239, T1646, R2004, B1680)
| ['状态栏', 'StatusBar', '状态栏StatusBar']
| child_window(title="状态栏", auto_id="1025", control_type="StatusBar")
| |
| | Static - '' (L239, T1648, R1359, B1680)
| | ['Static', 'Static0', 'Static1']
| |
| | Static - ' 第 7 行,第 12 列' (L1361, T1648, R1569, B1680)
| | ['Static2', ' 第 7 行,第 12 列Static', ' 第 7 行,第 12 列']
| | child_window(title=" 第 7 行,第 12 列", control_type="Text")
| |
| | Static - ' 100%' (L1571, T1648, R1644, B1680)
| | ['Static3', ' 100%Static', ' 100%']
| | child_window(title=" 100%", control_type="Text")
| |
| | Static - ' Windows (CRLF)' (L1646, T1648, R1824, B1680)
| | ['Static4', ' Windows (CRLF)', ' Windows (CRLF)Static']
| | child_window(title=" Windows (CRLF)", control_type="Text")
| |
| | Static - ' UTF-8' (L1826, T1648, R1980, B1680)
| | ['Static5', ' UTF-8Static', ' UTF-8']
| | child_window(title=" UTF-8", control_type="Text")
|
| TitleBar - '' (L263, T834, R2004, B876)
| ['TitleBar']
| |
| | Menu - '系统' (L239, T842, R272, B875)
| | ['系统Menu', 'Menu', '系统', '系统0', '系统1', 'Menu0', 'Menu1']
| | child_window(title="系统", auto_id="MenuBar", control_type="MenuBar")
| | |
| | | MenuItem - '系统' (L239, T842, R272, B875)
| | | ['系统MenuItem', 'MenuItem', '系统2', 'MenuItem0', 'MenuItem1']
| | | child_window(title="系统", control_type="MenuItem")
| |
| | Button - '最小化' (L1793, T832, R1864, B876)
| | ['最小化', '最小化Button', 'Button5']
| | child_window(title="最小化", control_type="Button")
| |
| | Button - '最大化' (L1864, T832, R1934, B876)
| | ['Button6', '最大化', '最大化Button']
| | child_window(title="最大化", control_type="Button")
| |
| | Button - '关闭' (L1934, T832, R2005, B876)
| | ['关闭Button', '关闭', 'Button7']
| | child_window(title="关闭", control_type="Button")
|
| Menu - '应用程序' (L239, T876, R2004, B905)
| ['应用程序Menu', '应用程序', 'Menu2']
| child_window(title="应用程序", auto_id="MenuBar", control_type="MenuBar")
| |
| | MenuItem - '文件(F)' (L239, T876, R311, B905)
| | ['文件(F)MenuItem', '文件(F)', 'MenuItem2']
| | child_window(title="文件(F)", control_type="MenuItem")
| |
| | MenuItem - '编辑(E)' (L311, T876, R383, B905)
| | ['编辑(E)MenuItem', '编辑(E)', 'MenuItem3']
| | child_window(title="编辑(E)", control_type="MenuItem")
| |
| | MenuItem - '格式(O)' (L383, T876, R460, B905)
| | ['格式(O)', '格式(O)MenuItem', 'MenuItem4']
| | child_window(title="格式(O)", control_type="MenuItem")
| |
| | MenuItem - '查看(V)' (L460, T876, R534, B905)
| | ['查看(V)MenuItem', 'MenuItem5', '查看(V)']
| | child_window(title="查看(V)", control_type="MenuItem")
| |
| | MenuItem - '帮助(H)' (L534, T876, R610, B905)
| | ['帮助(H)MenuItem', 'MenuItem6', '帮助(H)']
| | child_window(title="帮助(H)", control_type="MenuItem")
2、指定输出第2层,结果保存在文件output.txt中:
window.print_control_identifiers(depth=2, filename='output.txt')
Control Identifiers:
Dialog - 'test001.txt - 记事本' (L228, T831, R2015, B1691)
['Dialog', 'test001.txt - 记事本Dialog', 'test001.txt - 记事本']
child_window(title="test001.txt - 记事本", control_type="Window")
|
| Edit - '文本编辑器' (L239, T906, R2004, B1646)
| ['Edit']
| child_window(title="文本编辑器", auto_id="15", control_type="Edit")
|
| StatusBar - '状态栏' (L239, T1646, R2004, B1680)
| ['状态栏', '状态栏StatusBar', 'StatusBar']
| child_window(title="状态栏", auto_id="1025", control_type="StatusBar")
|
| TitleBar - '' (L263, T834, R2004, B876)
| ['TitleBar']
|
| Menu - '应用程序' (L239, T876, R2004, B905)
| ['应用程序', '应用程序Menu', 'Menu2']
| child_window(title="应用程序", auto_id="MenuBar", control_type="MenuBar")
以上是关于Pywinauto常用01--print_control_identifiers()的主要内容,如果未能解决你的问题,请参考以下文章