2

我正在尝试使用 pywinauto python 模块自动执行 teamcenter 的任务。但我无法使用 TreeViews 正常工作。每当我尝试使用 GetItem()、SubElements()、Item() 和 _treeview_element 下的许多其他函数时都会出现错误。请查看以下错误。

我正在使用 python 2.7,并且我还安装了 pywin32 模块

for i in range(tr.ItemCount()):

    print tr.GetItem(i)

回溯(最近一次通话最后):

File "<pyshell#61>", line 2, in <module>

print tr.GetItem(i)   File "C:\Users\patibj\Desktop\pywinauto-

master\pywinauto\controls\common_controls.py", line 1010, in GetItem
if isinstance(path[0], int):

TypeError: 'int' object has no attribute '__getitem__'

这是我尝试使用 GetChild()

a[0]  is <pywinauto.controls.common_controls._treeview_element object at 0x02EC11B0>  a[0].GetChild((1))

Traceback (most recent call last):

File "<pyshell#49>", line 1, in <module>

a[0].GetChild((1))

File "C:\Users\patibj\Desktop\pywinauto- master\pywinauto\controls\common_controls.py", line 840, in GetChild

return self.Children()[index]

File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 739, in Children

if self.Item().cChildren not in (0, 1):

File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 539, in Item

return self._readitem()[0]

File "C:\Users\patibj\Desktop\pywinauto-master\pywinauto\controls\common_controls.py", line 904, in _readitem

raise ctypes.WinError() WindowsError: [Error 0] The operation completed successfully.

请帮帮我。在此先感谢。

4

1 回答 1

0

TreeViewWrapper.GetItem()方法获取path参数,该参数应该是以反斜杠\\符号开头的字符串。例子:

app.Dialog.TreeView.GetItem('\\1st_level_item_name\\2ndlevelitem').Click()

对于按索引访问,请使用整数列表:

app.Dialog.TreeView.GetItem([1, 0])

GetChild() 与 explorer.exe TreeView 一起使用:

>>> tree.GetItem([1]).GetChild(2).Text()
u'Computer'
于 2015-07-02T13:51:58.530 回答