Downloaded pywinauto 6.4 using 64 bit python.
I got this code to work once... I left the whole interpreter session in notepad++. I came back to retrace my steps and now I can't get what was already working to work. Why can't I interact with the tree item? It worked the other day but now I can't seem to "see" any of the items in the tree even though they show up with print_control_identifiers()
It's a WPF application I connected to it after it was already open using:
>>> import pywinauto
>>> from pywinauto.application import Application
>>> app = Application(backend="uia").connect(title_re=".*POS UI", class_name="Window")
>>> app.POS_UI.draw_outline()
>>> dlg_Xtree1.print_control_identifiers()
Control Identifiers:
TreeView - 'POS_IntranetAPP_Tree1' (L-839, T-1164, R-643, B-925)
['TreeView', 'POS_IntranetAPP_Tree1TreeView', 'POS_IntranetAPP_Tree1']
child_window(title="POS_IntranetAPP_Tree1", auto_id="POS_IntranetAPP_Tree1", control_type="Tree")
|
| TreeItem - 'POS.Tree.Thing. ' (L-838, T-1163, R-707, B-1141)
| ['TreeItem', 'POS.Tree.Thing. ', 'POS.Tree.Thing. TreeItem', 'TreeItem0', 'TreeItem1', 'POS.Tree.Thing. 0', 'POS.Tree.Thing. 1', 'POS.Tree.Thing. TreeItem0', 'POS.Tree.Thing. TreeItem1']
| child_window(title="POS.Tree.Thing. ", control_type="TreeItem")
|
| TreeItem - 'POS.Tree.Thing. ' (L-838, T-1141, R-701, B-1119)
| ['TreeItem2', 'POS.Tree.Thing. 2', 'POS.Tree.Thing. TreeItem2']
| child_window(title="POS.Tree.Thing. ", control_type="TreeItem")
|
| TreeItem - 'POS.Tree.Thing. ' (L-838, T-1119, R-679, B-1097)
| ['TreeItem3', 'POS.Tree.Thing. 3', 'POS.Tree.Thing. TreeItem3']
| child_window(title="POS.Tree.Thing. ", control_type="TreeItem")
>>> dlg_Xtree1.treeitem2.expand
<bound method UIAWrapper.expand of <uia_controls.TreeItemWrapper -
'POS.Tree.Thing', TreeItem,
However now, even though it can see the "tree view" it's completely blind to the tree items. I tried reconnecting to the app thinking it might just not be refreshed. I just don't get it... It worked once but now no matter what I do I can't get it to function.
>>> dlg_Xtree1.TreeItem3.draw_outline()
pywinauto.findbestmatch.MatchError: Could not find 'TreeItem3' in 'dict_keys([])'
So Strangely, after I expanded the menu manually, I could then expand and collapse the same menu without changing my code at all. I'm not sure what that means or how to get around it.
Haha I went to test my hypothesis by closing everything and reopening back up and now I can't get it to work again. :(
Okay so now it seems like in order to bring that "window" to life you have to interact with the other controls. It's visible in inspect.exe and pywinauto can see it with print_control_identifiers() but can't interact with it.
If you use connect()
, always think about running script as Administrator. That might be a reason. With start()
the child process has usually the same privilege level and the problem doesn’t exist.