pywinuto -click_input()函数在树视图的随机节点上单击
我正在尝试自动化MMC(控制台中的SNAP)类型桌面应用程序。我需要在哪里展开树。
尝试1- 但是,当我确实使用Expand()
函数时,会生成错误弹出窗口,其中说“子节点不存在”。在此脚本停止之后,除非单击“错误”弹出窗口,否则在控制台上没有错误消息。我怀疑这是因为当树节点扩展时,它会触发一些事件,这些事件将儿童节点带到下面,而Pywinauto并没有吸引该节点的孩子。请注意,当步骤手动完成时,不会出现此错误弹出窗口。
尝试2 - 当我尝试使用select()
尝试时,观察到的行为与上述相同。它生成了相同的错误弹出窗口。
尝试3 - 我尝试了单击()
和click_input()
函数,然后在随机树节点上单击,但在其称为的树节点上没有。
以上所有试验都是我的应用,不是公开的。
为了重现此问题,我已经在Windows OS上的常见应用程序上尝试过它。我们可以看到第三次仍然可再现。
参考代码 -
import time
from pywinauto.application import Application
from pywinauto import Desktop
app = Application().start(r'cmd.exe /c "C:\Windows\system32\perfmon.msc"', wait_for_idle=False)
app = Application(backend="win32").connect(title='Performance Monitor', timeout=10)
main_wind = app.window(best_match='MMCMainFrame', top_level_only=False)
console_wind = main_wind.child_window(best_match="MDIClients").child_window(best_match='MMCChildFrm').child_window(class_name="MMCViewWindow")
tree = console_wind.TreeView # print_control_identifiers()
children = tree.get_item(["Performance","Data Collector Sets"]).expand().get_child("System").expand().get_child('System Diagnostics')
print(children.text())
# below line will select the System Diagnostics
children.select()
time.sleep(4)
# Below line should click on System Diagnostics but it does NOT and same happens for click() function
children.click_input()
任何帮助都将有助于知道为什么此conscrips()
和click_input()
单击随机树节点上的单击以及为什么evage> evagn()
和select()
方法生成非功能错误弹出窗口?
请提及是否有具体的解决方法。
版本 - Windows OS 10,构建20H2
Python 3.10.4 comtypes 1.1.11
PIP 22.0.4
pywin32 303
Pywinauto 0.6.8
setuptools 61.2.0
六个1.16.0
Wheel 0.37.1
Tia ..
我已经引用了一些堆栈溢出和GitHub问题跟踪器,如下所示,但无效。
I'm trying to automate the mmc (snap in console) type desktop app. Where I need to expand the tree.
Try 1 -
But when I do use expand()
function it generates error popup which says that "the child nodes does not exists". After this script simply stops with no error message on console unless ok button is clicked on error popup. This I suspect because when tree node expanded it triggers some event which brings child nodes under it and somehow pywinauto is not getting Childs of this node. Please note that this error popup does not come up when the step is done manually.
Try 2 -
When I tried with select()
then too same behavior observed as above. It generated same error popup.
Try 3 -
I tried click()
and click_input()
functions and it clicks on random tree node but not on the tree node on which it is called.
The all above trials are of my application which is not public.
For reproducing this issue I have tried it on common application available on windows OS. And we can see that the 3rd is still reproducible.
Reference code -
import time
from pywinauto.application import Application
from pywinauto import Desktop
app = Application().start(r'cmd.exe /c "C:\Windows\system32\perfmon.msc"', wait_for_idle=False)
app = Application(backend="win32").connect(title='Performance Monitor', timeout=10)
main_wind = app.window(best_match='MMCMainFrame', top_level_only=False)
console_wind = main_wind.child_window(best_match="MDIClients").child_window(best_match='MMCChildFrm').child_window(class_name="MMCViewWindow")
tree = console_wind.TreeView # print_control_identifiers()
children = tree.get_item(["Performance","Data Collector Sets"]).expand().get_child("System").expand().get_child('System Diagnostics')
print(children.text())
# below line will select the System Diagnostics
children.select()
time.sleep(4)
# Below line should click on System Diagnostics but it does NOT and same happens for click() function
children.click_input()
Any help will be really helpful in knowing why this click()
and click_input()
clicks on random tree node and Why expand()
and select()
method generates the non functional error popup?
Please mention if there is concrete workaround to this.
versions -
Windows OS 10, build 20H2
Python 3.10.4
comtypes 1.1.11
pip 22.0.4
pywin32 303
pywinauto 0.6.8
setuptools 61.2.0
six 1.16.0
wheel 0.37.1
TIA..
I have referenced some stack overflow and github issue tracker as for this problem as below but nothing works.
Treeview problem
select() for TreeView items (and similar) leads error if this selection calls other dialogs etc
Python: Click by coordinate inside a window
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这全是因为用于控制应用程序中的SNAP的不正确后端API。不幸的是,我在Win32 API上进行的POC,因为我正在手动执行一些初始步骤,因此我面临的问题(在Try1中解释)不在那里,一切都很好。
我将后端切换到UIA ,它为我提供了以前使用的控件的不同标识符。现在,我使用了这些标识符,并开始使用UIA文档,一切都开始顺利进行。
同样,在我的调查中,除非您尝试两者兼而有之,否则没有适当的方法来确定桌面应用程序的后端API。
对读者的建议 - 如果您使用Win32 API作为后端,则文档中有不同的API方法。对于UIA的后端不同。仔细阅读文档。
This was all because of incorrect backend API used for snap in control application. Unfortunately my POC I did on win32 API where it worked because I was doing some initial steps manually hence the problem I was facing(explained in try1) was not there and everything was working perfectly fine.
As soon as I switched the backend to UIA it gave me different identifiers for the controls that I used previously. Now I used this identifiers and started using UIA documentation and everything started working smoothly.
Also in my investigation there is no proper way to identify the backend API for the desktop application unless you try both and figure out which works for you.
Suggestion to readers - If you are using win32 API as backend there are different api methods available for that in the documentation. and for UIA backend different. read documentation carefully.
您可以尝试使用Uispy工具,并发现Perfmon.msc可以与UIA自动化
You can try the uispy tool and find that perfmon.msc can be automated with uia