Find Child Controls

Feb 8, 2009 at 5:08 PM

We have a control with an embedded text control.  In UISpy the parent is ControlType.Pane and the child is ControlType.Edit.  The Edit control doesn't have an Id only the parent does.  Currently we are find it as follows, but this is slow because it requires two round trips.  Position based search doesn't seem to help--should it?  Is there a better way to get the child Edit control?

 

oControlTest = moCurrentWindow.Get(

SearchCriteria.ByAutomationId(name)) as UIItem;
TextBox oControl = null;
AutomationElement oAEC = oControlTest.AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
if (oAEC != null) {
    oControl = new TextBox(oAEC, moCurrentWindow) as TextBox;
}

 

Coordinator
Feb 8, 2009 at 6:48 PM
position based search should help searching the first (pane) search. if there aren't too many items inside the pane then the second search should be trivial. which search is slowing down more?
Feb 9, 2009 at 12:19 PM

Each search seems to take a several seconds.  I don't have precise timing since they seem to take about the same time.  The fact that I need to do two searches is doubling that cost.  Is there no way to make one call to get the nested Edit control given the ID of its parent?

I was guessing that position based searching wasn't working because the AutomationElement.FindFirst call bypassed it but I also seem to have a problem with getting position based searching working.  I've coded it as follows, the xml files are generated for each modal window and the several main windows that open.

 

 

if (modalWindow) {
    oWin = moCurrentWindow.ModalWindow(name,
InitializeOption.NoCache.AndIdentifiedBy(name));
}
else {
    oWin = moCurrentApplication.GetWindow(
SearchCriteria.ByAutomationId(name), InitializeOption.NoCache.AndIdentifiedBy(name));
}

I stop and restart the application several times during the long tests then before my test driver (a Fitnesse-based program) ends I call:  oCurrentApplication.ApplicationSession.Save();

I don't see any improvement in speed when running the program again. 

 

Feb 9, 2009 at 7:02 PM
I don't always get an XML file created for a modal child window.  If I put an .ApplicationSession.Save();  call in immediately after closing the dialog the xml file is created.  Are there specific constraints around caching the lookup information for modal child windows, e.g., does the Save call need to be made before the parent window closes?

Even when calling Save() to force the creation of the xml file for the modal child window I don't see any performance increase when I run the program again.

Is there any harm / benefit in calling ApplicationSession.Save multiple times during a single run of a testing program?  For example, should I be calling it each time the program under test exits vs. calling it once at the end of a long sequence of tests that involve starting and exiting the program under test multiple times?  Currently I was only calling Save at the end of the long sequence.
Coordinator
Feb 15, 2009 at 12:06 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Feb 15, 2009 at 3:46 PM
Is the work item to create xml files for child windows and does this mean that caching to increase performance when using modal windows doesn't work as of the current release?

Any suggestion on how to address the original question (copied below) on how to improve the performance when I want to get the embedded children of a UI control?

We have a control with an embedded text control.  In UISpy the parent is ControlType.Pane and the child is ControlType.Edit.  The Edit control doesn't have an Id only the parent does.  Currently we find it as follows, but this is slow because it requires two round trips.  Position based search doesn't seem to help--should it?  Is there a better way to get the child Edit control?

 

oControlTest = moCurrentWindow.Get(

 

SearchCriteria.ByAutomationId(name)) as UIItem;
TextBox oControl = null;
AutomationElement oAEC = oControlTest.AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
if (oAEC != null) {
    oControl = new TextBox(oAEC, moCurrentWindow) as TextBox;
}

Coordinator
Feb 18, 2009 at 7:17 PM
I don't think it is possible to do from UIA API.