I have started to automate my windows application using coded UI tests recently and facing issue while accessing some of the MSAA control. I am hand coding my automation and do not want to add controls to UI Map and then use it.
The control on which I got stuck is a treeItem on a left pane which selects machine and details are displayed in left over client area at the center.
I have tried to search control using properties as shown by crosshair onto the UI control but in vain.
Below is the code I have tried -
UITestControl machine = new UITestControl(App);
machine.TechnologyName = "MSAA";
machine.SearchProperties.Add(WinTreeItem.PropertyNames.ControlType, "TreeItem");
machine.SearchProperties.Add(WinTreeItem.PropertyNames.Name, "Machine1");
machine.SearchProperties.Add(WinTreeItem.PropertyNames.ControlName, "m_tvPlantStructureView");
Mouse.Click(machine); // This code gives an error
ERROR-
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details: TechnologyName: 'MSAA' ControlType: 'TreeItem' Name: 'Machine1' ControlName: 'm_tvPlantStructureView' ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
Refer to attachments. Let me know, what is the problem and what process to follow to completely get away of such kind of errors of controls not recognized in future.
Currently, I follow the method of doing a crosshair and getting properties and then coding on that property of control to automate user actions and assertions. But this way does not always work.
Let me know if there is any better way of doing it.