selecting combobox item using ui automation

后端 未结 9 1894
猫巷女王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 03:17

    There isn't a big change but only a few to notice,

    1. Don't need to use collapse pattern, calling expand will do the trick for you.
    2. Using treescope.subtree worked for me instead of children.

    The code sample would be like this,

    public static void SelectValueInComboBox(string comboBox, string value)
    {
        var comboBoxElement = HelperMethods.FindElementFromAutomationID(comboBox);
        if (comboBoxElement == null)
            throw new Exception("Combo Box not found");
    
        ExpandCollapsePattern expandPattern = (ExpandCollapsePattern)comboBoxElement.GetCurrentPattern(ExpandCollapsePattern.Pattern);
    
        AutomationElement comboboxItem = comboBoxElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, value));
    
        SelectionItemPattern selectPattern = (SelectionItemPattern)comboboxItem.GetCurrentPattern(SelectionItemPattern.Pattern);
        selectPattern.Select();
    }
    

提交回复
热议问题