Search code examples
flaui

(FlaUI) CombBox does not have Items, Select() does not work


I am using FlaUI on top of my XUnit to do the test, but the ComboBox doesn't seem to work. I was able to retrieve the ComboBox object, but it does not have any Items and Select() doesn't work either. What am I missing?

there's code snippet:

ComboBox box = createWOForm.ComboRoutingCode; // box returns the object
box.Focus();
int i = box.Items.Count(); // not Items...yes, I have visually check the UI...the ComboBox has items

enter image description here


Solution

  • I ended up create an extension to the ComboBox (FlaUI)...the key here is you have to use the the ExpandCollapsePattern to manipulate the UI:

    internal static bool SelectItem(this ComboBox combo, string displayToSelect)
    {
      IExpandCollapsePattern pattern = combo.Patterns.ExpandCollapse.Pattern;
      pattern.Expand();
    
      ComboBoxItem selectedItem = combo.Select(displayToSelect);
    
      return selectedItem != null;
    }