Pywinauto: RuntimeError: We should never get to this part of ListView.get_item()

Pywinauto: RuntimeError: We should never get to this part of ListView.get_item()

我正在尝试使用 pywinauto 从我的 windows 应用程序的对话框的列表视图控件中获取文本。下面是代码片段和错误。

*from pywinauto.application import Application  
app = Application().connect(handle=0x00C21210)  
dlg = app.window(handle=0x00D70EDE)  
dlg.ListView.texts()*  

**Error:** RuntimeError: We should never get to this part of ListView.get_item(), retval = 0, GetLastError() = 0, item_index = 0, subitem_index = 0  

而且,这是该对话框控件 print_control_identifiers return

   | ListView - ''    (L49, T162, R785, B530)  
   | ['ListView', u'Rate File Path:ListView']  
   | child_window(class_name="WindowsForms10.SysListView32.app.0.378734a")  
   |    |  
   |    | Header - ''    (L51, T164, R783, B181)  
   |    | [u'Rate File Path:Header', 'Header']  
   |    | child_window(class_name="SysHeader32")  

我还编辑了此 post 以获得如下 inspect.exe 结果:

How found:  Mouse move (480,279)  
    hwnd=0x008615AA 64bit class="WindowsForms10.SysListView32.app.0.378734a" style=0x56010141 ex=0x200  
ControlType:    UIA_ListControlTypeId (0xC358)  
LocalizedControlType:   "list"  
BoundingRectangle:  {l:23 t:136 r:759 b:504}  
IsEnabled:  true  
IsOffscreen:    false  
IsKeyboardFocusable:    true  
HasKeyboardFocus:   true  
ProcessId:  25412  
RuntimeId:  [2A.8615AA]  
AutomationId:   "8787370"  
FrameworkId:    "WinForm"  
ClassName:  "WindowsForms10.SysListView32.app.0.378734a"  
NativeWindowHandle: 0x8615AA  
ProviderDescription:    "[pid:26132,hwnd:0x8615AA Annotation:Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll); Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]"  
IsPassword: false  
FillColor:  [Not supported]
OutlineColor:   [Not supported]
OutlineThickness:   [Not supported]
FillType:   [Not supported]
CenterPoint:    [Not supported]
Rotation:   [Not supported]
Size:   [Not supported]
VisualEffects:  [Not supported]
LegacyIAccessible.ChildId:  0
LegacyIAccessible.Role: list (0x21)
LegacyIAccessible.State:    focused,focusable (0x100004)
Selection.CanSelectMultiple:    false
Selection.IsSelectionRequired:  true
Selection.Selection:    
IsAnnotationPatternAvailable:   false
IsDragPatternAvailable: false
IsDockPatternAvailable: false
IsDropTargetPatternAvailable:   false
IsExpandCollapsePatternAvailable:   false
IsGridItemPatternAvailable: false
IsGridPatternAvailable: false
IsInvokePatternAvailable:   false
IsItemContainerPatternAvailable:    false
IsLegacyIAccessiblePatternAvailable:    true
IsMultipleViewPatternAvailable: false
IsObjectModelPatternAvailable:  false
IsRangeValuePatternAvailable:   false
IsScrollItemPatternAvailable:   false
IsScrollPatternAvailable:   false
IsSelectionItemPatternAvailable:    false
IsSelectionPatternAvailable:    true
IsSpreadsheetItemPatternAvailable:  false
IsSpreadsheetPatternAvailable:  false
IsStylesPatternAvailable:   false
IsSynchronizedInputPatternAvailable:    false
IsTableItemPatternAvailable:    false
IsTablePatternAvailable:    false
IsTextChildPatternAvailable:    false
IsTextEditPatternAvailable: false
IsTextPatternAvailable: false
IsTextPattern2Available:    false
IsTogglePatternAvailable:   false
IsTransformPatternAvailable:    false
IsTransform2PatternAvailable:   false
IsValuePatternAvailable:    false
IsVirtualizedItemPatternAvailable:  false
IsWindowPatternAvailable:   false
IsCustomNavigationPatternAvailable: false
FirstChild: (null) header
LastChild:  (null) list item
Next:   "X" button
Previous:   "Y" button
Other Props:    Object has no additional properties
Children:   (null) header
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
    (null) list item
Ancestors:  "A" window
    "Workspace" pane
    "C" window
    "Desktop" pane
    [ No Parent ]

你需要安装64位Python + pywinauto。它可以自动化 32 位和 64 位应用程序。或者使用 Application(backend="uia") 和 Inspect.exe 作为间谍工具。对于 WinForms 应用程序可能更好,并且不限制您使用 64 位 Python。

P.S。我会尝试重现它并在下一个版本中添加一些更明确的错误消息。