当我们使用pywinauto连接到UIA后端窗口时,出现找不到元素的错误。
下面是我尝试过的代码。当执行uia后端应用程序时,如果应用程序最小化,我将收到以下元素未找到错误。同时,如果应用程序在后台窗口中运行且没有最小化,则一切正常!!!
'''This part of code only for the testing purpose'''
app = pywinauto.Application(backend="uia")
app.connect(path="C:\xyz\Exe\Service\abc.exe")
window = app.window_(title=u'abc')
if window.is_minimized():
window.restore()
window.wait('ready', timeout=10)
# window.print_control_identifiers()
button = window.child_window(title="Ramping settings...")
button.click()
print("END-->Exec")
Traceback (most recent call last):
File "C:/Projects/TestAutomation/TBricks/Interface/UI/TBrickUIApp.py", line 124, in <module>
if window.is_minimized():
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 367, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 248, in __resolve_control
raise e.original_exception
pywinauto.findwindows.ElementNotFoundError: {'process': 7108, 'backend': u'uia', 'title': u'PPHSControl'}
答案 0 :(得分:1)
我知道在创建窗口句柄时错过了一个错误/参数。
window = app.window_(title=u'PPHS', visible_only=False).restore()
如果最小化,上述代码将恢复。