question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to identify objects in WPF Winform10 application

See original GitHub issue

Platform: Window Server 2016 64 Bit Language: Python 2.7 IDE: Visual Studio Code pywinauto V0.6.6

I am attempting to automate a DotNet application. pywinauto appears to correctly find some windows and buttons(if I am very broad in defining the object properties) but I seam to be completely unable to identify TreeView’s. If there is a tree view on the page pretty much everything else can not be found either.

I have attached properties as identified by Microsoft SDK Inspect tool. The only object I can identify is the MainContextManagementPage using:

contextManagement = Application().connect(title_re="Context Management.*", timeout=20)

Using either backend="uia" or backend="win32" makes no difference to finding the other objects:

Using debugger I can see the code does not appear to identify any of the objects I am looking for: TreeViewWrapper(pywinauto.findwindows.find_windows(best_match=u'TreeView',top_level_only=False)[0]) MatchError: Could not find 'TreeView' in '[u'', u'Chrome_WidgetWin_1', u'MSTaskSwWClass', u'Running applicationsMSTaskListWClass', u'User Promoted Notification AreaToolbar', u'TrayNotifyWnd', u'Start', u'Touch keyboard', u'Touch keyboardTIPBand', u'ApplicationFrameTitleBarWindow', u'8', u'5', u'Action Center', 'Toolbar2', u'FolderView', u'Context Management - HwndWrapper[BLAH.exe;;468c-b7f5-efb281f5f434]', u'ApplicationFrameWindow', u'Shell_TrayWnd', u'User Promoted Notification Area', u'MyLibrary.py - MyAutomation - Visual Studio Code [Administrator]', u'Action CenterButton', u'System Clock, 2:47 PM, \u200e5/\u200e20/\u200e2019TrayClockWClass', u'MyLibrary.py - MyAutomation - Visual Studio Code [Administrator]Shell_TrayWnd', u'Context Management', u'ApplicationFrameInputSinkWindow', u'1', u'0', u'3', u'2', u'Running applications', u'4', u'Program Manager', u'6', u'7', u'System Promoted Notification Area', u'System Promoted Notification AreaToolbar', 'ListView', u'Running applicationsMSTaskSwWClass', u'Program ManagerProgman', u'Running applications1', u'Running applications0', u'Windows Ink WorkspaceTrayNotifyWnd', 'ReBar', u'DummyDWMListenerWindow', u'HwndWrapper[DMD.exe;;cd7d7cb9-8684-468c-b7f5-efb281f5f434]', u'Action CenterButton2', u'Action CenterButton1', u'Windows Ink Workspace', u'Button', u'Button2', u'Button1', u'Search WindowsButton', u'EdgeUiInputTopWndClass', u'Button5', u'Button4', u'SHELLDLL_DefView', u'Task ViewButton', u'Toolbar0', u'Action CenterButton0', u'TIPBand', u'FolderViewListView', u'TrayClockWClass', u'Button3', u'MyLibrary.py - MyAutomation - Visual Studio Code [Administrator]Chrome_WidgetWin_1', u'Search Windows', u'Task View', 'Pager', u'Toolbar1', u'Running applications2', u'MSTaskListWClass', u'Button0', 'Toolbar', u'Task ViewReBar', u'Progman', u'System Clock, 2:47 PM, \u200e5/\u200e20/\u200e2019', u'StartStart', u'Windows Ink WorkspaceButton', u'Button6']'

Any help would be greatly appreciated. Using UFT(which I dont want to use) I can see the objects can be identified as expected.

Window("Program Manager").WinListView("SysListView32").Activate "APP"
SwfWindow("Configuration Selector").SwfButton("OK").Click
WpfWindow("Context Management").("contextTreeView").Select "RealTime;MYLINK);RealTime"
WpfWindow("Context Management").WpfButton("Connect to Context").Click

ButtonObjectProperties.txt MainContextManagementPageProperties.txt TreeViewItemObjectProperties.txt TreeViewObjectProperties.txt

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vorwerkkcommented, May 29, 2019

Thank you. Was great to see the draw_outline() in action. Yes I found your suggestion of: contextManagementWindow.child_window(auto_id=“id_RealTime1”, control_type=“TreeItem”).select() worked using the .select(). Unfortunately I found the auto_id would be difficult to predict with char replacement and duplication. I have however found a solution as per below: If you think there is anything I can do to simplify or fix please let me know. Thank you so much for the support.

def run_uia(self, applicationPath):
        from pywinauto import Application, Desktop
        from pywinauto.controls.uia_controls import (TreeViewWrapper)
        contextPath = "RealTime\MYBLAH (Model version: 513.20, 2/2/2019 6:21:33 PM)\RealTime"
        contextPathList = contextPath.split("\\")
        
        contextManagementApp = Application(backend="uia").connect(title_re="Context Management.*", timeout=20)
        contextManagementWindow = contextManagementApp.window(title_re="Context Management.*")

        pathSuccesfullySelected = self.find_and_open_tree_view(contextManagementWindow,contextPathList)

        if pathSuccesfullySelected:
            contextManagementWindow.ConnectToContext.click()
        else:
            assert False
def find_and_open_tree_view(self,contextManagementWindow,contextPathList):
        currLogger.logMessage("info", "find_and_open_tree_view Start:")
        contextManagementWindowdescs = contextManagementWindow.descendants()
        itemFoundAndSelected = False
        for desc in contextManagementWindowdescs:
            descendantProperties = desc.get_properties()
            currLogger.logMessage("debug", "Current class_name is: " + descendantProperties['friendly_class_name'] + "\n")
            if "TreeView" == str(descendantProperties['friendly_class_name']):
                #currLogger.logMessage("debug", "descendantProperties: is a: " + descendantProperties['friendly_class_name'] + "\n")
                
                treeRootItems = desc.roots()
                treeItemCount = 0
                
                for treeItem in treeRootItems:
                    itemFoundAndSelected = self.find_and_open_tree_item(treeItem,contextPathList,treeItemCount)
                    if itemFoundAndSelected:
                        break
            if itemFoundAndSelected:
                        break
        
        return itemFoundAndSelected
    def find_and_open_tree_item(self,currTreeItem,contextPathList,treeItemCount):
        currLogger.logMessage("info", "check_and_open_tree_item Start:")
        itemFoundAndSelected = False
        contextPathListLength = len(contextPathList)-1

        childTreeItemProperties = currTreeItem.get_properties()

        currLogger.logMessage("debug", "Current class_name is: " + str(childTreeItemProperties['friendly_class_name']) + " - Child Text is: " + str(currTreeItem.children_texts()[treeItemCount]) + "\n")
        
        if ("TreeItem" == str(childTreeItemProperties['friendly_class_name'])) and (contextPathList[treeItemCount] in currTreeItem.children_texts()):

            if contextPathListLength == treeItemCount:
                currTreeItem.select()
                itemFoundAndSelected = True
            elif contextPathListLength < treeItemCount:
                itemFoundAndSelected = False
            else:
                currTreeItemChildren = currTreeItem.children()
                
                for childItem in currTreeItemChildren:
                    childItemProperties = childItem.get_properties()
                    
                    if "TreeItem" == str(childItemProperties['friendly_class_name']):
                        itemFoundAndSelected = self.find_and_open_tree_item(childItem,contextPathList,treeItemCount+1)
                        if itemFoundAndSelected:
                            break

        return itemFoundAndSelected

I am not sure if there are any future changes that could be made to the framework to handle tree structures like this?

0reactions
vasily-v-ryabovcommented, May 30, 2019

Ok, then try desc.element_info.control_type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Known Issues - .NET WPF - ADM Help Centers
Object Identification ​​ Workaround: Close your WPF application. In UFT One, open the Record and Run Settings dialog box (Record > Record and...
Read more >
WPF/XAML Property not found on 'object' - Stack Overflow
To fix it, find the TextBlock and the Binding and either swap the object with an instance of your class that does have...
Read more >
How to: Find an Element by Its Name - WPF .NET Framework
void Find(object sender, RoutedEventArgs e) { object wantedNode = stackPanel.FindName("dog"); if (wantedNode is TextBlock) { // Following ...
Read more >
Problem in identifying an object with in a WPF table.
We have an application with WPF GUI and we have textbox objects within WPF ... I could not get why it is unable...
Read more >
WPF Designer: Unable to cast object type 'Mocks ...
The application compiles and runs just fine, but this error is constantly reported in Visual Studio, making it diffucult to find *real* errors....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found