Skip to main content
 首页 » 编程设计

python之使用 pywinauto 查找 GUI 元素

2025年05月04日22unruledboy

我正在尝试使用 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 自动化框架?

请您参考如下方法:

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

window.PrintControlIdentifiers() 

或

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