我刚刚开始学习python。现在我的工作是尝试使用pywinauto来做一些自动测试。有时我可以通过ParentDlg.child_window(**criterion)
得到一个对话框,有时不行。你知道吗
你可以考虑我的申请(页面管理器.exe)有两个按钮,[Page1]按钮和[Page2]按钮。当应用程序启动时,您可以单击按钮启动页面.exe过程。也就是说有两个页面.exe同时。什么时候页面.exe开始了,开始了图像计算.exe. 所以有两个图像计算.exe两个。的父对话框图像计算.exe是页面.exe. 你知道吗
当您点击[Page1]按钮时页面.exe(用于第1页)显示并页面.exe(用于第2页)被隐藏。当您点击[Page2]按钮时页面.exe(用于第2页)显示并页面.exe(用于第1页)被隐藏。你知道吗
我的问题是页面.exe显示,例如页面.exe(用于第1页)。我可以找到的主要对话页面.exe通过ParentDlg = Desktop(backend="uia").window(best_match="Page1")
。之后,我使用psutil.pids()
和进程名"ImageCalculate.exe"
得到图像计算.exe例如,一个是1234,另一个是5678。请注意,二号图像计算.exe具有几乎相同的属性、相同的标题、类名等。
最后我试着得到的主要对话图像计算.exe通过ParentDlg.child_window(**criterion)
。你知道吗
但根据我的测试,有时我可以得到主对话框并继续操作它的控件,有时不行。我不知道为什么,我希望有人能帮助我或提供另一种方式来获得主对话框的图像计算.exe. 因为我有图像计算.exe,也许我可以通过PID获得进程的主对话框?然后也许我可以检查这个对话框是否显示,以确认这个对话框属于哪一个页面.exe(如果显示此对话框,我认为此对话框属于第1页的页面.exe的图像计算.exe). 你知道吗
ParentDlg = Desktop(backend="uia").window(best_match="Page1")
// pids contains two pid of ImageCalculate.exe
for pid in pids:
try:
criterion = {}
criterion['class_name_re'] = "AfxFrameOrView*"
criterion['process']=pid
ImageCalculate_dialog = parent.child_window(**criterion)
# I think if ImageCalculate_dialog.writable_props is successful.
# Page1’s Page.exe’s ImageCalculate.exe's main dialog is found.
# But some times ImageCalculate_dialog.writable_props is failed two times and throws ElementNotFoundError
_cname = ImageCalculate_dialog.writable_props
except pywinauto.findwindows.ElementNotFoundError:
continue
else:
return ImageCalculate_dialog
# Now I am trying to use following codes to get main dialog
ImageCalculateApp = Application().connect(process=pid)
dialogs = ImageCalculateApp.windows()
for dialog in dialogs:
print(dialog)
# When I check print result in console
# I can find "hwndwrapper.DialogWrapper - 'ImageCalculate - Untitled',Afx:00400000:b:00010003:00000006:003908A5"
# But I don't know how to use hwndwrapper.DialogWrapper object,
# who could tell me how to use this object or give me some documents about this object?
目前没有回答
相关问题 更多 >
编程相关推荐