【问题标题】:Finding GUI elements with pywinauto使用 pywinauto 查找 GUI 元素
【发布时间】:2015-05-24 11:52:27
【问题描述】:

我正在尝试使用 pywinauto。 现在我想使用print_control_identifiers(),但我得到了错误,但是我编写了我的代码——我无法获得关于 GUI 对象的任何信息。 我已经尝试通过swapy 生成代码 - 生成了很多代码,但没有成功。

这是我目前的代码:

import getpass, fnmatch

from pywinauto import application

currentUser = getpass.getuser()

if fnmatch.fnmatch(currentUser, "axe"):
    pwa_app = application.Application()
    w_handle = application.findwindows.find_windows(title=u'Login - 0.9.347', class_name='WindowsForms10.Window.8.app.0.141b42a_r11_ad1')[0]
    window = pwa_app.window_(handle=w_handle)
    window.SetFocus()
    ctrl = window['Log In']
    ctrl.Click()


else:
    print "You need admin rights for that action"

你能告诉我,我需要在哪里使用print_control_identifiers()吗? 您还有其他更新的 GUI 自动化框架吗?

【问题讨论】:

  • 脚本输出是什么? pywinauto 可以与许多 Windows 窗体控件一起使用。
  • 你为什么不用pwa_app = application.Application().connect_(path='your.exe)? find_windows 应该是内部人员。 pwa_app.Window_(title=u'Login - 0.9.347', class_name='...') 返回几乎相同的 WindowSpecification 对象。

标签: python user-interface automation pywinauto


【解决方案1】:

PrintControlIdentifiers() 对于顶层窗口很有用。如果window 是顶级窗口规范,那么只需调用

window.PrintControlIdentifiers()

 pwa_app.Window_(title=u'Login - 0.9.347', top_level_only=True).PrintControlIdentifiers()

【讨论】:

    【解决方案2】:

    几个例子:

    Swapy 可以很好地识别属性。此外,使用 pywinauto 给出的示例也很有帮助。 来源:https://pywinauto.googlecode.com/hg/pywinauto/docs/getting_started.html

    from pywinauto import application
    
    app = application.Application.Start("Notepad.exe")
    app.Notepad.print_control_identifiers()
    app.Notepad.MenuSelect("Edit->Replace")
    app.Replace.print_control_identifiers()
    

    从 pywinauto 导入应用程序

    from pywinauto import application
    app = application.Application()
    app.Start("Notepad.exe")
    Wnd_Main = app.window_(title_re=".*Notepad")
    Wnd_Main.MenuSelect("File->Save")
    
    Wnd_Save = app.window_(title_re="Save As")
    Wnd_Save.Edit1.SetEditText("Hello World.txt")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 1970-01-01
      • 1970-01-01
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      相关资源
      最近更新 更多