我正在尝试使用pywinauto python模块自动执行teamcenter的任务。但是我无法使用TreeViews正常工作。当我试图使用GetItem(),SubElements(),Item()和_treeview_element下的许多其他函数给出错误时。请查看下面的错误。
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.
请帮帮我。谢谢。
答案 0 :(得分: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'