Search code examples
pywinauto

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


I am trying to get the texts from listview control of a dialog from my windows application using pywinauto. The below is the code snippet and error.

*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  

And, here is what the print_control_identifiers return for that dialog control

   | 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")  

I have also edited this post to have the inspect.exe findings as below:

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 ]

Solution

  • You need to install 64-bit Python + pywinauto. It can automate both 32- and 64-bit apps. Or use Application(backend="uia") and Inspect.exe as a spy tool. It might be better for WinForms apps and don't limit you to 64-bit Python.

    P.S. I will try to reproduce it and add some more clear error message in next versions.