ComboBox as TextBox

Apr 14, 2008 at 12:44 PM
In our application, we have a editable combobox. You can either select the value as a dropdown, or you can type the value in directly.

I tried to get the item as a TextBox, but that didnt work and I couldn't see a way to set its text, or add my own ListItems to be able to select.

Any ideas?
Coordinator
Apr 14, 2008 at 6:43 PM
OK, I think this is an issue?
For now you can do a comboBox.Click() or Focus and then use keyboard class to end the text. Please use the window.attachedkeyboard.
Nov 5, 2008 at 11:33 PM
Hi.

I am also trying to set the text in an editable Win32ComboBox.

With the latest release (v0.17) how can this be achieved?

Thank you.
Nov 6, 2008 at 9:26 AM
Have you tried vivek's approach?
Just do:
comboBox.Click();
Keyboard.Instance.Enter("valueToEnter");

José Tavares
Nov 6, 2008 at 10:55 PM
Thank you, José.

That worked! :)
Coordinator
Nov 9, 2008 at 11:43 AM
If this is WinForm application, then you can cast the ComboBox to WinFormComboBox and set the text.
Mar 4, 2010 at 1:26 PM

How can i get TextBox from editable ComboBox in WPF with white and C#

i have simple app which has one editable comboBox

Uispy shows that comboBox has TextBox inside it

but if i try

var textBox  = editableComboBox.Get<TextBox>(SearchCriteria.ByAutomationId("name"))

it returns an error

Test threw exception:  System.NullReferenceException: Object reference not set to an instance of an object..

 

I need that TextBox because i need to get editable comboBox value which is not in editable comboBox listBox

Uispy shows it in Value

but white doesnt have this command

string text = editableComboBox.Value();

or

string text = editableComboBox.Text()

 

Mar 4, 2010 at 1:35 PM

Hi

 

Try

 

 

AutomationElement element = editableComboBox.AutomationElement.FindFirst( TreeScope.Children, 
                                                                          new PropertyCondition( AutomationElement.AutomationIdProperty,"automationID"));

TextBox box = new TextBox(element, editableComboBox.ActionListener);

 

 

 

Mar 4, 2010 at 1:48 PM
Edited Mar 4, 2010 at 1:49 PM

thanks, that works :)

 

if i will use this

var element= editableComboBox.GetElement(SearchCriteria.ByAutomationId("automationID"));

var textBox = new TextBox(element, editableComboBox.ActionListener);

 

instead of

AutomationElement element = editableComboBox.AutomationElement.FindFirst( TreeScope.Children,
                                                                          new PropertyCondition( AutomationElement.AutomationIdProperty,"automationID"));

var box = new TextBox(element, editableComboBox.ActionListener);

boths ways works, which is better?

Mar 4, 2010 at 2:05 PM
Edited Mar 4, 2010 at 2:07 PM

GetElement search on all descendents, so it is a deeper search.

My solution might be faster if the tree is deeper.

But here I think it would be the same effect.

 

 

Mar 18, 2010 at 1:24 PM

Hi, now i need to get element with index 1

var element= editableComboBox.GetElement(SearchCriteria.ByAutomationId("automationID").AndIndex(1));

but this line returns 

threw exception:  System.NullReferenceException: Object reference not set to an instance of an object

Mar 18, 2010 at 1:27 PM

what do you search for can you show a hirarchical view startting with the combobox?

 

use LogStructure to get Information

 

Mar 18, 2010 at 1:40 PM
Edited Mar 18, 2010 at 1:41 PM

AutomationId: 
ControlType: ControlType.ListItem
Name: { Door = MDP.SID.DB.KN_Door, Permissions = System.Linq.Lookup`2+Grouping[MDP.SID.DB.KN_Door,MDP.SID.DB.KN_AccessLevelPermission] }
HelpText: 
Bounding rectangle: 2451,202,498,59
ClassName: ListBoxItem
IsOffScreen: False
FrameworkId: WPF
ProcessId: 3168

System.Windows.Automation.SelectionItemPattern
System.Windows.Automation.ScrollItemPattern

    AutomationId: 
    ControlType: ControlType.List
    Name: 
    HelpText: 
    Bounding rectangle: 2793,207,127,48
    ClassName: ListView
    IsOffScreen: False
    FrameworkId: WPF
    ProcessId: 3168

    System.Windows.Automation.SelectionPattern

        AutomationId: 
        ControlType: ControlType.ListItem
        Name: MDP.SID.DB.KN_AccessLevelPermission
        HelpText: 
        Bounding rectangle: 2793,207,127,24
        ClassName: ListBoxItem
        IsOffScreen: False
        FrameworkId: WPF
        ProcessId: 3168

        System.Windows.Automation.SelectionItemPattern
        System.Windows.Automation.ScrollItemPattern

            AutomationId: directionImage
            ControlType: ControlType.Image
            Name: 
            HelpText: Entry
            Bounding rectangle: 2795,210,20,17
            ClassName: Image
            IsOffScreen: False
            FrameworkId: WPF
            ProcessId: 3168


            AutomationId: AI_timeZoneListComboBox
            ControlType: ControlType.ComboBox
            Name: 
            HelpText: 
            Bounding rectangle: 2819,209,99,20
            ClassName: ComboBox
            IsOffScreen: False
            FrameworkId: WPF
            ProcessId: 3168


            System.Windows.Automation.SelectionPattern
            System.Windows.Automation.ExpandCollapsePattern

                AutomationId: PART_EditableTextBox
                ControlType: ControlType.Edit
                Name: 
                HelpText: 
                Bounding rectangle: 2824,211,4,15
                ClassName: TextBox
                IsOffScreen: True
                FrameworkId: WPF
                ProcessId: 3168

                System.Windows.Automation.ValuePattern
                System.Windows.Automation.TextPattern

                AutomationId: 
                ControlType: ControlType.ListItem
                Name: 
                HelpText: 
                Bounding rectangle: Empty
                ClassName: ListBoxItem
                IsOffScreen: True
                FrameworkId: WPF
                ProcessId: 3168

                System.Windows.Automation.SelectionItemPattern
                System.Windows.Automation.ScrollItemPattern

                AutomationId: 
                ControlType: ControlType.ListItem
                Name: 
                HelpText: 
                Bounding rectangle: Empty
                ClassName: ListBoxItem
                IsOffScreen: True
                FrameworkId: WPF
                ProcessId: 3168

                System.Windows.Automation.SelectionItemPattern
                System.Windows.Automation.ScrollItemPattern

                AutomationId: 
                ControlType: ControlType.ListItem
                Name: 
                HelpText: 
                Bounding rectangle: Empty
                ClassName: ListBoxItem
                IsOffScreen: True
                FrameworkId: WPF
                ProcessId: 3168

                System.Windows.Automation.SelectionItemPattern
                System.Windows.Automation.ScrollItemPattern

        AutomationId: 
        ControlType: ControlType.ListItem
        Name: MDP.SID.DB.KN_AccessLevelPermission
        HelpText: 
        Bounding rectangle: 2793,231,127,24
        ClassName: ListBoxItem
        IsOffScreen: False
        FrameworkId: WPF
        ProcessId: 3168

        System.Windows.Automation.SelectionItemPattern
        System.Windows.Automation.ScrollItemPattern

            AutomationId: directionImage
            ControlType: ControlType.Image
            Name: 
            HelpText: Exit
            Bounding rectangle: 2795,233,20,19
            ClassName: Image
            IsOffScreen: False
            FrameworkId: WPF
            ProcessId: 3168


            AutomationId: AI_timeZoneListComboBox
            ControlType: ControlType.ComboBox
            Name: 
            HelpText: 
            Bounding rectangle: 2819,233,99,20
            ClassName: ComboBox
            IsOffScreen: False
            FrameworkId: WPF
            ProcessId: 3168


            System.Windows.Automation.SelectionPattern
            System.Windows.Automation.ExpandCollapsePattern

                AutomationId: PART_EditableTextBox
                ControlType: ControlType.Edit
                Name: 
                HelpText: 
                Bounding rectangle: 2824,235,4,15
                ClassName: TextBox
                IsOffScreen: True
                FrameworkId: WPF
                ProcessId: 3168

                System.Windows.Automation.ValuePattern
                System.Windows.Automation.TextPattern

                AutomationId: 
                ControlType: ControlType.ListItem
                Name: 
                HelpText: 
                Bounding rectangle: Empty
                ClassName: ListBoxItem
                IsOffScreen: True
                FrameworkId: WPF
                ProcessId: 3168

                System.Windows.Automation.SelectionItemPattern
                System.Windows.Automation.ScrollItemPattern

                AutomationId: 
                ControlType: ControlType.ListItem
                Name: 
                HelpText: 
                Bounding rectangle: Empty
                ClassName: ListBoxItem
                IsOffScreen: True
                FrameworkId: WPF
                ProcessId: 3168

                System.Windows.Automation.SelectionItemPattern
                System.Windows.Automation.ScrollItemPattern

                AutomationId: 
                ControlType: ControlType.ListItem
                Name: 
                HelpText: 
                Bounding rectangle: Empty
                ClassName: ListBoxItem
                IsOffScreen: True
                FrameworkId: WPF
                ProcessId: 3168

                System.Windows.Automation.SelectionItemPattern
                System.Windows.Automation.ScrollItemPattern

    AutomationId: AI_deleteDoorButton
    ControlType: ControlType.Button
    Name: 
    HelpText: Delete door
    Bounding rectangle: 2922,221,20,20
    ClassName: Button
    IsOffScreen: False
    FrameworkId: WPF
    ProcessId: 3168

    System.Windows.Automation.InvokePattern

        AutomationId: 
        ControlType: ControlType.Image
        Name: 
        HelpText: 
        Bounding rectangle: 2924,223,16,16
        ClassName: Image
        IsOffScreen: False
        FrameworkId: WPF
        ProcessId: 3168

Mar 18, 2010 at 1:45 PM

http://www.ipix.lt/desc/71062507/

 

this picture shows uispy

Mar 18, 2010 at 2:10 PM
Edited Mar 18, 2010 at 2:12 PM

ok and which of these elements is the element you search for?

 

I think you search a ListItem correct?

 

or do you search for one of the ComboBoxes?

Mar 19, 2010 at 10:35 AM
Edited Mar 19, 2010 at 10:38 AM

I need these comboBoxes that i've marked in red

there is two of them.

the first i can get simly, but the second one i think i need to get it with adding command .AndIndex(1)

AutomationId: AI_timeZoneListComboBox
            ControlType: ControlType.ComboBox\

 

Stack trace:

 

Test method TestApp.TestAccessLevelTab.Test threw exception:  System.NullReferenceException: Object reference not set to an instance of an object..
at White.Core.AutomationElementSearch.AutomationSearchCondition.Satisfies(AutomationElement element) in AutomationSearchCondition.cs: line 114
at White.Core.AutomationElementSearch.RawAutomationElementFinder.Find(AutomationElement automationElementAutomationSearchCondition automationSearchCondition) in RawAutomationElementFinder.cs: line 37
at White.Core.AutomationElementSearch.RawAutomationElementFinder.Find(AutomationElement automationElementAutomationSearchCondition automationSearchCondition) in RawAutomationElementFinder.cs: line 39
at White.Core.AutomationElementSearch.RawAutomationElementFinder.Find(AutomationElement automationElementAutomationSearchCondition automationSearchCondition) in RawAutomationElementFinder.cs: line 39
at White.Core.AutomationElementSearch.RawAutomationElementFinder.Descendant(AutomationSearchCondition automationSearchCondition) in RawAutomationElementFinder.cs: line 28
at White.Core.AutomationElementSearch.AutomationElementFinder.FindDescendantRaw(AutomationSearchCondition automationSearchCondition) in AutomationElementFinder.cs: line 113
at White.Core.UIItems.UIItem.GetElement(SearchCriteria searchCriteria) in UIItem.cs: line 350
at TestApp.TestBase.GetItem<T>(UIItem itemString nameInt32 indexNullable`1 isCritical) in TestBase.cs: line 309
at TestApp.TestAccessLevelTab.CheckIsSchedulesAssigned(ListItem itemBoolean isCritical) in TestAccessLevelTab.cs: line 188
at TestApp.TestAccessLevelTab.CheckListBox(TabPage tabBoolean shouldBeEnabledAndVisibleInt32 nrString nameBoolean isCritical) in TestAccessLevelTab.cs: line 164
at TestApp.TestAccessLevelTab.SelectAndCheckAccessLevel(TabPage tabString nameBoolean shouldBeEnabledAndVisibleInt32 nrBoolean isCritical) in TestAccessLevelTab.cs: line 105
at TestApp.TestAccessLevelTab.ExecuteTest() in TestAccessLevelTab.cs: line 37
at TestApp.TestBase.Test() in TestBase.cs: line 126

 

 

 

Program text:

 

        protected T GetItem<T>(UIItem item, string name, bool? isCritical) where T : UIItem
        {
            var result = GetItem<T>(item, name, 0, isCritical);
            return result;
        }
        protected T GetItem<T>(UIItem item, string name, int index, bool? isCritical) where T : UIItem
        {
            T uiItem = default(T);
            for (int i = 0; i < 3; i++)
            {
                AutomationElement element=null;
                if (index == 0)
                {
                    element = item.GetElement(SearchCriteria.ByAutomationId(name));
                }
                else if(index != 0)  
                {
                    element = item.GetElement(SearchCriteria.ByAutomationId(name).AndIndex(index));  //white bug, don't work
                }
                if (element != null)
                {                    
                    uiItem = (T) Activator.CreateInstance(typeof (T), element, item.ActionListener);
                    break;
                }
            }
            if (isCritical != null)
            {
                string text = string.Format("[isCritical={2}]Can't find {0} '{1}'", typeof (T).Name, name, isCritical);
                AssertIfFalse(uiItem != null, text, (bool) isCritical);
            }
            if (uiItem != null)
            {
                uiItem.Focus();
                AttachedKeyboard keyboard = MainWindow.Keyboard;
                if (uiItem is ComboBox)
                {
                    keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.F4);
                    keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.ESCAPE);
                }
            }
            return uiItem;
        }     

        protected T GetItem<T>(UIItem item, string name, bool? isCritical) where T : UIItem

        {

            var result = GetItem<T>(item, name, 0, isCritical);

            return result;

        }

 

        protected T GetItem<T>(UIItem item, string name, int index, bool? isCritical) where T : UIItem

        {

            T uiItem = default(T);

            for (int i = 0; i < 3; i++)

            {

                AutomationElement element=null;

                if (index == 0)

                {

                    element = item.GetElement(SearchCriteria.ByAutomationId(name));

                }

                else if(index != 0)  

                {

                    element = item.GetElement(SearchCriteria.ByAutomationId(name).AndIndex(index));  

                }

                if (element != null)

                {                    

                    uiItem = (T) Activator.CreateInstance(typeof (T), element, item.ActionListener);

                    break;

                }

            }

            if (isCritical != null)

            {

                string text = string.Format("[isCritical={2}]Can't find {0} '{1}'", typeof (T).Name, name, isCritical);

                AssertIfFalse(uiItem != null, text, (bool) isCritical);

            }

            if (uiItem != null)

            {

                uiItem.Focus();

                AttachedKeyboard keyboard = MainWindow.Keyboard;

                if (uiItem is ComboBox)

                {

                    keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.F4);

                    keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.ESCAPE);

                }

            }

            return uiItem;

        }     

 

Mar 19, 2010 at 11:02 AM

Hi

 

two ways to get what you want:

 

1.

IUIITem[] boxes = window.GetMultiple(SearchCriteria.ByAutomationId(id))  // maybe GetMultiple(SearchCriteria.ByControlType(ControlType.WPFComboBox).AndByAutomationId(id))

now you get a list with all comboboxes (you should cast to WPFComboBox)

 

if this not work

AutomationElementCollection elements = item.AutomationElement.FindAll(TreeScope.Descandents, new PropertyCondition(AutomationElement.AutomationIdProperty, "id");

List<WPFComboBox> list = new List<WPFCombobox>();
foreach(AutomationElement element in elements)
{
  list.Add(new WPFComboBox(element, window.ActionListener); //window is your window element whcih contains the textbox
}

 

 


 

 

Mar 19, 2010 at 11:26 AM

Thanks, that works