pywinauto中的print_control_identifiers()错误

时间:2016-12-30 04:04:57

标签: python pywinauto

我在WIN10中使用pyautowin,我想打开一个安全的应用程序来生成密码。但是当我在脚本中找到应用程序窗口后,print_control_identifiers()函数弹出错误,我不确定哪里出错了。错误窗口?应用中没有控件?请查看以下错误。

这样的代码:

from pywinauto.application import Application
app=Application()
app.start('C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe')
RSA=app.window_(title='000131843108 - RSA SecurID Token')
print RSA
print RSA.print_control_identifiers()

这样的错误:

2016-12-30 11:54:01,525 INFO: Imported existing <module 'comtypes.gen' from         'C:\Python27\lib\site-packages\comtypes\gen\__init__.pyc'>
2016-12-30 11:54:01,526 INFO: Using writeable comtypes cache directory: 'C:\Python27\lib\site-packages\comtypes\gen'  
<pywinauto.application.WindowSpecification object at 0x039EA670>
Traceback (most recent call last):
  File "C:/New folder/ConnectVPN.py", line 7, in <module>
    print RSA.print_control_identifiers()
  File "C:\Python27\lib\site-packages\pywinauto\application.py", line 569, in print_control_identifiers
    this_ctrl = self.__resolve_control(self.criteria)[-1]
  File "C:\Python27\lib\site-packages\pywinauto\application.py", line 239, in __resolve_control
    raise e.original_exception
pywinauto.findwindows.ElementNotFoundError: {'process': 4064, 'backend': u'win32', 'title': '000131843108 - RSA SecurID Token'}

我的应用就像:

enter image description here

1 个答案:

答案 0 :(得分:0)

你的应用程序启动缓慢吗?如果超过5秒,主窗口可能尚不存在,并引发异常。只需使用RSA.wait('ready', timeout=10)确保窗口在print_control_identifiers()之前存在。