【问题标题】:GetItem(),ItemCount(),SubElements() functions not working in pywinautoGetItem(),ItemCount(),SubElements() 函数在 pywinauto 中不起作用
【发布时间】:2015-09-20 01:25:55
【问题描述】:

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

我使用的是 python 2.7,我也安装了 pywin32 模块

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

    print tr.GetItem(i)

Traceback(最近一次调用最后一次):

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.

请帮帮我。在此先感谢。

【问题讨论】:

    标签: python python-2.7 automation pywin32 pywinauto


    【解决方案1】:

    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'
    

    【讨论】:

    • 另外,当我尝试使用 GetChild() 函数或 SubElements() 函数时,我总是会收到上面提到的错误。你能帮我解决这个问题吗?
    • 即使是 &lt;pywinauto.controls.common_controls._treeview_element object at 0x033AC430&gt;,当我尝试使用 Text() 函数时,我也会遇到这种错误。我想问题出在 _readitem()
    • 可能我需要有关您的案例的更多信息:Windows 版本(Win7?Win8.1?64 位还是 32 位?),您的应用程序和 Python 是 64 位/32 位吗?我可以下载您的应用二进制文件并查看更多详细信息吗?
    • 您的应用程序是用 Unicode 字符集构建的吗?这一点很重要。似乎 TVM_GETITEMW 返回非空值。如果您在项目属性中使用“多字节字符集”,可能会出现这种情况。
    • 你可以调用tr.IsUnicode(),它返回哪个值?
    猜你喜欢
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多