在自动化特定应用程序时,我遇到一个问题,即重启后我使用runonce注册表设置运行脚本。该脚本可以正常运行,但是在打开应用程序后,该脚本会给出pywinauto文件夹完整路径的运行时错误,例如:.../Python/Scripts/Pywinauto
和错误消息Application not loaded properly
。
我知道pywinauto能够在runonce阶段进行初始化存在一个问题,这可能会导致打开新窗口很困难。但是,它会打开所需的窗口,但无法从那里进行必要的单击,脚本关闭。如果启动后执行该脚本,则脚本运行良好。 我正在Windows Server 2012 R2 x64计算机上工作,并在最新版本的pywinauto中使用python 3.6(如果有帮助)。 我应该如何进行呢?请要求澄清或可能需要的任何信息。
编辑: 在我的代码中,句柄值未发送到hwnd变量。
代码:
while(True):
try:
## App is open. Click inside the app and open new window
hwnd = pywinauto.findwindows.find_windows(title = "window_title") # Check if window exists
print(hwnd)
if (hwnd[0]!=None): #since findwindows returns a list
break
except Exception:
#handle exception
#Perform action on the new window
输出:
[] #Hwnd list is empty even if the window exists
P.S我没有使用exist()方法,因为它没有给出异常,并且会一次又一次地打开同一窗口。