【问题标题】:How to test Window Application by pywinauto如何通过 pywinauto 测试窗口应用程序
【发布时间】:2019-11-29 08:10:45
【问题描述】:

我有以下来自网站的代码副本:https://pywinauto.github.io/

from pywinauto.application import Application
app = Application().start("notepad.exe")
app.UntitledNotepad.menu_select("Help->About Notepad")
app.AboutNotepad.OK.click()
app.UntitledNotepad.Edit.type_keys("pywinauto Works!", with_spaces = True)

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

谢谢!!!

【问题讨论】:

    标签: python frameworks pywinauto


    【解决方案1】:
    >>> 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
    

    https://pywinauto.readthedocs.io/en/latest/getting_started.html

    【讨论】:

    • 我在下面写代码: app = Application().start("notepad.exe") app.Notepad.menu_select("Help->About Notepad") window = app.top_window() 窗口。 print_control_identifiers() 但它不显示 Ok 控制信息
    【解决方案2】:

    我在下面写代码:

        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
    

    【讨论】:

    • 表示您没有打印完整的输出。如果您打印所有内容,则确定按钮是列表。
    • 如何打印所有内容?请帮帮我
    • app.AboutNotepad.dump_tree() ?对于Application(backend="win32"),子对话框是另一个顶级窗口。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多