selecting combobox item using ui automation

后端 未结 9 1904
猫巷女王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:57

    I think this might be the easiest way for a simple generic ComobBox value setter this one is fine provided the list items in the ComboBox doesn't have duplicates.

    private void SetCombobValueByUIA( AutomationElement ctrl, string newValue )
    { 
        ExpandCollapsePattern exPat = ctrl.GetCurrentPattern(ExpandCollapsePattern.Pattern) 
                                                                  as ExpandCollapsePattern;
    
        if( exPat== null )
        {
            throw new ApplicationException( "Bad Control type..." );
        }
    
        exPat.Expand();
    
        AutomationElement itemToSelect = ctrl.FindFirst(TreeScope.Descendants, new
                              PropertyCondition(AutomationElement.NameProperty,newValue));
    
        SelectionItemPattern sPat = itemToSelect.GetCurrentPattern(
                                                  SelectionItemPattern.Pattern)  as SelectionItemPattern ; 
        sPat. Select();
    }
    

提交回复
热议问题