我已经使用 pywinauto 连接到一个 Windows 应用程序,如下所示,
import subprocess
sp = subprocess.call("start shell:AppsFolder\myapp!App", shell=True)
from pywinauto import application
app = application.Application(backend="uia")
my_app = app.connect(title="myapp", class_name="ApplicationFrameWindow")
但这是通过 Python 的 RPyC 连接。
第一次,这段代码可以正常工作,但是如果我使用相同的 RPyC 连接再次运行我的脚本,我会看到以下错误:
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 944, in connect
self.process = findwindows.find_element(**kwargs).process_id
File "C:\Python27\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element
elements = find_elements(**kwargs)
File "C:\Python27\lib\site-packages\pywinauto\findwindows.py", line 197, in find_elements
cache_enable=True)
File "C:\Python27\lib\site-packages\pywinauto\uia_element_info.py", line 272, in children
return self._get_elements(IUIA().tree_scope["children"], cond, cache_enable)
File "C:\Python27\lib\site-packages\pywinauto\uia_element_info.py", line 261, in _get_elements
ptrs_array = self._element.FindAll(tree_scope, cond)
COMError: (-2147024809, 'The parameter is incorrect.', (None, None, None, 0, None))
如果我关闭现有的 RPyC 连接并打开另一个会话,那么上面的代码可以正常工作。我无法弄清楚为什么我会看到这个错误。有任何想法吗?