selecting combobox item using ui automation

后端 未结 9 1895
猫巷女王i
猫巷女王i 2021-02-06 02:45

how do I select ComboBox\'s SelectedIndex = -1?

I wrote a code to automate testing:

AutomationElement aeBuildMachine = null;
int count =         


        
9条回答
  •  梦如初夏
    2021-02-06 02:58

      public static void SetComboBox(AutomationElement ComboxBox, string SelectedValue)
            {
                AutomationElement ListBox = ComboxBox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "ListBox"));
                AutomationElement SelectedItem = ListBox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, SelectedValue));
                ((SelectionItemPattern)SelectedItem.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();
            }
    

    Instruction on how to use: 1) Copy and Paste into Utility Class 2) Find your ComboBox AutomationElement 3) Utility.SetCombox(ComboxAutomationElement, "SelectedText")

    To understand:

    Tree structure of ComboBox as follow:

    ComboBox->ListBox (children)->ListItems(children) [each combobox has a ListBox as a child, and the ListBox has all ListItems as children].

    Each ListItem has SelectedItemPattern, invoke which you want to select.

    I later found out that "Shaz " has better coding, and i vote him as the best code.

    ** Comment: To do UIAAutomation, you must map the AutomationElements of your application to a TreeView, which makes everything simple and understood.

提交回复
热议问题