Python 如何使用pywinauto测试窗口应用程序

Python 如何使用pywinauto测试窗口应用程序,python,frameworks,pywinauto,Python,Frameworks,Pywinauto,我有以下网站的代码副本:: 我有一个问题是:如何知道记事本有无记事本控制。我使用Autoit获取控件信息,但无法获取某些控件的信息,无法获取UntitledNotepad控件,但为什么上面的代码在记事本中知道UntitledNotepad。请告诉我如何知道记事本中是否存在UnttledNotepad控件 谢谢 >>> from pywinauto.application import Application >>> app = Application().st

我有以下网站的代码副本::

我有一个问题是:如何知道记事本有无记事本控制。我使用Autoit获取控件信息,但无法获取某些控件的信息,无法获取UntitledNotepad控件,但为什么上面的代码在记事本中知道UntitledNotepad。请告诉我如何知道记事本中是否存在UnttledNotepad控件

谢谢

>>> from pywinauto.application import Application
>>> app = Application().start("notepad.exe")
>>> window = app.top_window ()
>>> window.print_control_identifiers ()
Control Identifiers:

Notepad - 'Untitled - Notepad'    (L183, T308, R1798, B937)
['Untitled - NotepadNotepad', 'Untitled - Notepad', 'Notepad']
child_window(title="Untitled - Notepad", class_name="Notepad")
   |
   | Edit - ''    (L191, T359, R1790, B929)
   | ['Untitled - NotepadEdit', 'Edit']
   | child_window(class_name="Edit")
   |
   | StatusBar - ''    (L191, T906, R1790, B929)
   | ['StatusBar   Ln 1, Col 1  ', 'StatusBar', 'Untitled - NotepadStatusBar']
   | child_window(class_name="msctls_statusbar32")
>>> window = app.window (best_match = "UntitledNotepad")
>>> window.exists ()
True
>>> window = app["UntitledNotepad"]
>>> window.exists ()
True
>>> window = app.UntitledNotepad
>>> window.exists ()
True
>>> window = app.window (best_match = "Untitled - Notepad")
>>> window.exists ()
True
>>> window = app["Untitled - Notepad"]
>>> window.exists ()
True
>>> window.menu_select("Help->About Notepad")
>>> window.exists ()
True
>>> window = app.window (class_name="Notepad")
>>> window.exists ()
True
>>> window = app.window (title="Untitled - Notepad")
>>> window.exists ()
True
我写代码如下:

    app = Application().start("notepad.exe")
    app.Notepad.menu_select("Help->About Notepad")
    window = app.top_window()    
    window.print_control_identifiers()
    Starting test: EmptyProject.Test.Test
20191219 16:37:39.197 : INFO : Control Identifiers:

Dialog - 'About Notepad'    (L1019, T401, R1610, B930)
['About NotepadDialog', 'Dialog', 'About Notepad']
child_window(title="About Notepad", class_name="#32770")
   | 
   | Static - ''    (L1085, T543, R1582, B545)
   | ['Static', 'About NotepadStatic', 'Static0', 'Static1', 'About NotepadStatic0', 'About NotepadStatic1']
   | child_window(class_name="Static")
   | 
   | Static - ''    (L1079, T563, R1116, B603)
   | ['Static2', 'About NotepadStatic2']
   | child_window(class_name="Static")
   | 
   | Static - 'Microsoft Windows'    (L1128, T563, R1531, B583)
   | ['Static3', 'Microsoft Windows', 'Microsoft WindowsStatic']
   | child_window(title="Microsoft Windows", class_name="Static")
   | 
   | Static - 'Version 1809 (OS Build 17763.557)'    (L1128, T583, R1592, B603)
   | ['Static4', 'Version 1809 (OS Build 17763.557)', 'Version 1809 (OS Build 17763.557)Static']
   | child_window(title="Version 1809 (OS Build 17763.557)", class_name="Static")
   | 
   | Static - '© 2018 Microsoft Corporation. All rights reserved.'    (L1128, T603, R1548, B623)
   | ['© 2018 Microsoft Corporation. All rights reserved.', '© 2018 Microsoft Corporation. All rights reserved.Static', 'Static5', '© 2018 Microsoft Corporation. All rights reserved.Static0', '© 2018 Microsoft Corporation. All rights reserved.Static1']
   | child_window(title="© 2018 Microsoft Corporation. All rights reserved.", class_name="Static")
   | 
   | Static - ''    (L1128, T623, R1548, B643)
   | ['© 2018 Microsoft Corporation. All rights reserved.Static2', 'Static6']
   | child_window(class_name="Static")
   | 
   | Static - 'The Windows 10 Enterprise operating system and its user interface are protected by trademark and other pending or existing intellectual property rights in the United States and other countries/regions.'    (L1128, T643, R1548, B723)
   | ['Static7', 'The Windows 10 Enterprise operating system and its user interface are protected by trademark and other pending or existing intellectual property rights in the United  <truncated>
Ending test: EmptyProject.Test.Test
但它不显示关于记事本视图的Ok按钮信息

它仅显示以下信息:

    app = Application().start("notepad.exe")
    app.Notepad.menu_select("Help->About Notepad")
    window = app.top_window()    
    window.print_control_identifiers()
    Starting test: EmptyProject.Test.Test
20191219 16:37:39.197 : INFO : Control Identifiers:

Dialog - 'About Notepad'    (L1019, T401, R1610, B930)
['About NotepadDialog', 'Dialog', 'About Notepad']
child_window(title="About Notepad", class_name="#32770")
   | 
   | Static - ''    (L1085, T543, R1582, B545)
   | ['Static', 'About NotepadStatic', 'Static0', 'Static1', 'About NotepadStatic0', 'About NotepadStatic1']
   | child_window(class_name="Static")
   | 
   | Static - ''    (L1079, T563, R1116, B603)
   | ['Static2', 'About NotepadStatic2']
   | child_window(class_name="Static")
   | 
   | Static - 'Microsoft Windows'    (L1128, T563, R1531, B583)
   | ['Static3', 'Microsoft Windows', 'Microsoft WindowsStatic']
   | child_window(title="Microsoft Windows", class_name="Static")
   | 
   | Static - 'Version 1809 (OS Build 17763.557)'    (L1128, T583, R1592, B603)
   | ['Static4', 'Version 1809 (OS Build 17763.557)', 'Version 1809 (OS Build 17763.557)Static']
   | child_window(title="Version 1809 (OS Build 17763.557)", class_name="Static")
   | 
   | Static - '© 2018 Microsoft Corporation. All rights reserved.'    (L1128, T603, R1548, B623)
   | ['© 2018 Microsoft Corporation. All rights reserved.', '© 2018 Microsoft Corporation. All rights reserved.Static', 'Static5', '© 2018 Microsoft Corporation. All rights reserved.Static0', '© 2018 Microsoft Corporation. All rights reserved.Static1']
   | child_window(title="© 2018 Microsoft Corporation. All rights reserved.", class_name="Static")
   | 
   | Static - ''    (L1128, T623, R1548, B643)
   | ['© 2018 Microsoft Corporation. All rights reserved.Static2', 'Static6']
   | child_window(class_name="Static")
   | 
   | Static - 'The Windows 10 Enterprise operating system and its user interface are protected by trademark and other pending or existing intellectual property rights in the United States and other countries/regions.'    (L1128, T643, R1548, B723)
   | ['Static7', 'The Windows 10 Enterprise operating system and its user interface are protected by trademark and other pending or existing intellectual property rights in the United  <truncated>
Ending test: EmptyProject.Test.Test
启动测试:清空project.test.test
20191219 16:37:39.197:信息:控制标识符:
对话框-“关于记事本”(L1019、T401、R1610、B930)
['About notepadialog'、'Dialog'、'About Notepad']
子窗口(title=“关于记事本”,class_name=“#32770”)
| 
|静态-“”(L1085、T543、R1582、B545)
|['Static','About NotepadStatic','Static0','Static1','About NotepadStatic0','About NotepadStatic1']
|子窗口(class\u name=“Static”)
| 
|静态-“”(L1079、T563、R1116、B603)
|['Static2','About NotepadStatic2']
|子窗口(class\u name=“Static”)
| 
|静态-“Microsoft Windows”(L1128、T563、R1531、B583)
|['Static3'、'Microsoft Windows'、'Microsoft Windows Static']
|子窗口(title=“Microsoft Windows”,class\u name=“静态”)
| 
|静态-“版本1809(操作系统构建17763.557)”(L1128、T583、R1592、B603)
|['Static4'、'Version1809(OS Build 17763.557)'、'Version1809(OS Build 17763.557)Static']
|子窗口(title=“Version1809(OS Build 17763.557)”,class\u name=“Static”)
| 
|静态-©2018微软公司。保留所有权利。”(L1128、T603、R1548、B623)
|['©2018微软公司。保留所有权利。','©2018微软公司。保留所有权利。静态','静态5','©2018微软公司。保留所有权利。静态0','©2018微软公司。保留所有权利。静态1']
|子窗口(title=“©2018 Microsoft Corporation.保留所有权利。”,class_name=“Static”)
| 
|静态-“”(L1128、T623、R1548、B643)
|['©2018微软公司。保留所有权利。Static2'、“Static6']
|子窗口(class\u name=“Static”)
| 
|静态—“Windows 10企业操作系统及其用户界面受美国和其他国家/地区的商标和其他未决或现有知识产权的保护。”(L1128、T643、R1548、B723)
|['Static7','Windows 10企业操作系统及其用户界面受美国商标和其他未决或现有知识产权的保护
结束测试:清空project.test.test

I编写以下代码:app=Application().start(“notepad.exe”)app.notepad.menu\u select(“Help->About notepad”)window=app.top\u window()window.print\u control\u identifiers()但它不显示Ok control info表示您没有打印完整输出。如果您打印所有内容,则会列出Ok按钮。如何打印所有内容?请帮助我
app.AboutNotepad.dump_tree()
?在
应用程序(backend=“win32”)
的情况下,子对话框是另一个顶级窗口。