TextBox in TextBox

Jan 13, 2010 at 2:43 PM

Hi

we have a TextBox in a TextBox (WPF)

Here some code:

 

TextBox text =
          _container.Get<TextBox>(SearchCriteria.ByControlType(ControlType.Edit).AndAutomationId(_automationID));
        if (_isCapsulatedItem)
        {
          AutomationElement element = text.AutomationElement.FindFirst(TreeScope.Children,
                                                                       new PropertyCondition(
                                                                         AutomationElement.AutomationIdProperty,
                                                                         "PART_Textbox"));
          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?

 

Throndorin

Coordinator
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.

 

Throndorin