尽管在Pywinauto

时间:2018-02-07 09:11:37

标签: pywinauto

使用64位python下载pywinauto 6.4。

我让这段代码工作了一次......我把整个解释器会话留在了记事本++中。我回来追溯我的步骤,现在我无法得到已经起作用的东西。为什么我不能与树项交互?它在前几天工作但现在我似乎无法“看到”树中的任何项目,即使它们出现在print_control_identifiers()

这是一个WPF应用程序,它在使用以下方式打开后连接到它:

>>> 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, 

然而现在,即使它可以看到“树视图”,它对树项完全失明。我尝试重新连接到应用程序,认为它可能不会被刷新。我只是不明白......它工作了一次,但现在无论我做什么,我都无法让它发挥作用。

>>> dlg_Xtree1.TreeItem3.draw_outline() pywinauto.findbestmatch.MatchError: Could not find 'TreeItem3' in 'dict_keys([])'

所以奇怪的是,在我手动扩展菜单之后,我可以扩展并折叠相同的菜单而根本不更改我的代码。我不确定这意味着什么或如何解决它。

哈哈,我通过关闭所有内容然后重新打开来测试我的假设,现在我无法让它重新开始工作。 :(

好的,现在好像为了将“窗口”变为现实,你必须与其他控件进行交互。它在inspect.exe中可见,pywinauto可以使用print_control_identifiers()查看它,但无法与之交互。

1 个答案:

答案 0 :(得分:0)

如果您使用connect(),请始终考虑以管理员身份运行脚本。这可能是一个原因。对于start(),子进程通常具有相同的权限级别,并且该问题不存在。