TextBox in TextBox

Jan 13, 2010 at 2:43 PM


we have a TextBox in a TextBox (WPF)

Here some code:


TextBox text =
        if (_isCapsulatedItem)
          AutomationElement element = text.AutomationElement.FindFirst(TreeScope.Children,
                                                                       new PropertyCondition(
          TextBox part = new TextBox(element, text.ActionListener);
          value = part.Text;

this example works

but why not



TextBox text = _container.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Edit).AndAutomationId(_automationID));
        if (_isCapsulatedItem)
          TextBox text = _container.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Edit).AndAutomationId("PART_Textbox"));
          value = part.Text;


Where is the difference?



Jan 17, 2010 at 1:11 PM

I see one difference, in first case you haven't specified that you are looking for a ControlType.Edit which is the extra filter condition in the second case.

Jan 18, 2010 at 5:53 AM

yes you are right

I will try without ControlType


but in fact I use always ControlType to be sure there is no second element with the  same name but other type.


UISpy show me that the controlType is Edít so I use it.