我的应用程序是使用InstallShield打包的。执行exe时发生的第一件事是提取msi文件;这大约需要10秒。
在msi提取完成之前,我无法找到我的主窗口,所以我使用time.sleep。然后我查找并找到我的窗口的句柄。但是对app.window_(handle=1234).Wait("enabled",timeout=25,retry_interval=0.5)的调用失败了,出现了这些错误消息。
*C:\python32>python test.py
| [2558122] |
Traceback (most recent call last):
File "test.py", line 16, in <module>
dlg = app.Window_(handle=hwnd).Wait("enabled", timeout=25, retry_interval=0.
5)
File "C:\python32\lib\site-packages\pywinauto\application.py", line 380, in Wa
it
WaitUntil(timeout, retry_interval, lambda: self.__check_all_conditions(check
_method_names))
File "C:\python32\lib\site-packages\pywinauto\timings.py", line 292, in WaitUn
til
func_val = func(*args)
File "C:\python32\lib\site-packages\pywinauto\application.py", line 380, in <l
ambda>
WaitUntil(timeout, retry_interval, lambda: self.__check_all_conditions(check
_method_names))
File "C:\python32\lib\site-packages\pywinauto\application.py", line 337, in __
check_all_conditions
check = getattr(self, check_name)
File "C:\python32\lib\site-packages\pywinauto\application.py", line 252, in __
getattr__
ctrls = _resolve_control(self.criteria)
File "C:\python32\lib\site-packages\pywinauto\application.py", line 755, in _r
esolve_control
criteria)
File "C:\python32\lib\site-packages\pywinauto\timings.py", line 356, in WaitUn
tilPasses
func_val = func(*args)
File "C:\python32\lib\site-packages\pywinauto\application.py", line 522, in _g
et_ctrl
findwindows.find_window(**criteria[0]))
File "C:\python32\lib\site-packages\pywinauto\controls\HwndWrapper.py", line 1
80, in __new__
new_class = cls.FindWrapper(handle)
File "C:\python32\lib\site-packages\pywinauto\controls\HwndWrapper.py", line 1
12, in FindWrapper
class_name = handleprops.classname(handle)
File "C:\python32\lib\site-packages\pywinauto\handleprops.py", line 94, in cla
ssname
win32functions.GetClassName (handle, ctypes.byref(class_name), 256)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: Don't know how to convert
parameter 1*这就是代码。我是一个有经验的程序员,但是是一个Python新手。我花了一整天的时间,用谷歌搜索了我的大脑,尝试了我能想到的所有方法。提前谢谢。
from pywinauto import application
from pywinauto import findwindows
app = application.Application()
app.start("MyInstallShieldApp.exe")
time.sleep(15)
hwnd=findwindows.find_windows(title=u"InstallShield Wizard", class_name="MsiDialogCloseClass")
print ("|", str(hwnd), "|")
dlg = app.Window_(handle=hwnd).Wait("enabled", timeout=25, retry_interval=0.5)发布于 2016-03-16 16:09:15
hwnd中的问题是一个列表,但是handle=hwnd需要一个整数。您应该使用find_window而不是find_windows,或者只使用hwnd中的第一个句柄,例如
hwnd = findwindows.find_windows(... dlg = app.Window_(handle=hwnd[0])...
对于你来说,使用pywinauto的SWAPY - UI检查器和代码生成器也会很有用。
发布于 2018-02-09 02:30:43
这个问题已经提了一年了,但希望它能帮助其他处于同样境地的人。我最初有一些类似于OP的东西,但完全迷惑了,因为我认为它会像pywinauto github存储库中提供的7zip installation example一样简单。然而,我发现实际的安装是在第二个过程中打开的,这与使用Application().start()打开应用程序以同时启动和挂钩程序的观点相去甚远。
我所做的是使用Windows SDK中的Inspect程序来定位元素的名称,以及在InstallShield完成提取.msi文件后保存它们的窗口。我没有使用start()打开InstallShield可执行文件,而是使用subprocess模块的popen()函数打开安装程序,然后在通过InstallShield解压后使用Application().connect()挂接到安装程序。下面是我为获得此功能所做的粗略版本,将我的发现与示例、文档和操作混合在一起:
import time
import subprocess
from pywinauto import application
# Open the module via Popen
# I tried using run() first but that prevented the click for reasons unknown
subprocess.Popen(r"C:\Users\fixer446\My Documents\InstallationFiles\Setup.exe")
# Let InstallShield extract the files and the installer load completely
time.sleep(15)
# Hook onto the newly opened setup window
app = application.Application().connect(title="Setup.WindowName", class_name="MsiDialogCloseClass")
# Work with the window and the controls within as advertised in pywinauto
# You may have to play around with this a little
installer = app["Setup.WindowName"]
installer["Next >"].Wait("enabled")
installer["Next >"].Click()希望这能有所帮助。
发布于 2016-03-17 16:56:35
app.Window_(...)可以接受与find_windows(...)相同的参数。是啊,现在文档里还没有高亮显示。但是代码可能会更短:
from pywinauto import application
from pywinauto import findwindows
app = application.Application()
app.start("MyInstallShieldApp.exe")
# the dialog may not exist yet here
dlg_spec = app.Window_(title=u"InstallShield Wizard", class_name="MsiDialogCloseClass")
# after this line the dialog exists or exception is raised
dlg = dlg_spec.Wait("enabled", timeout=25, retry_interval=0.5)
# dlg is a DialogWrapper object (for really existing dialog)您可以在this answer中阅读有关2级WindowSpecification概念的更多详细说明。
我将把它与即将到来的pywinauto 0.6.0 (稍晚一点)一起移到文档中。
https://stackoverflow.com/questions/36024849
复制相似问题