-->

pywinauto is_visible throwing exception instead of

2019-08-03 19:34发布

问题:

For the code below, I check whether the window exists and also if it is visible or not. Case is that the Exists returns true (But the window is hidden). So I have put another check is_visible. But is_visible is throwing an exception instead of returning true/false

dlg = app.window_(title_re = "Buy Order Entry.*")
if(dlg.Exists(1)):
    #Code enters here but window is hidden
    visible = app.window_(title_re = "Buy Order Entry.*").is_visible()

Output:

Traceback (most recent call last):
  File "autoscript.py", line 924, in <module>
    visible = app.window_(title_re = "Buy Order Entry.*").is_visible()
  File "C:\Python27\lib\site-packages\pywinauto\application.py", line 357, in __getattribute__
    ctrls = self.__resolve_control(self.criteria)
  File "C:\Python27\lib\site-packages\pywinauto\application.py", line 239, in __resolve_control
    raise e.original_exception
pywinauto.findwindows.ElementNotFoundError: {'process': 2164, 'title_re': 'Buy Order Entry.*', 'backend': u'win32'}
  File "C:\Python27\lib\site-packages\pywinauto\application.py", line 239, in __resolve_control
    raise e.original_exception
pywinauto.findwindows.ElementNotFoundError: {'process': 2164, 'title_re': 'Buy Order Entry.*', 'backend': u'win32'}

How can I solve this? Does is_visible has issues when used with regular expression for window titles?

回答1:

Good question. Probably there is a bug. Default search criteria contain visible_only=True by default (it's not mentioned in the exception message though). Sorry, can't promise to fix it fast (there are a couple of problems).

To workaround it I'd recommend using dlg.wait('visible', timeout=1) in try/except block. It should work fine.



标签: pywinauto