Ejemplo n.º 1
0
        protected AutomationElement FindUIAControl(XmlNode control)
        {
            string controlName = GetAttributeValue(control, "name", "");

            AutomationElement rootAutomationElement = this.RootAutomationElement;

            if (control != null)
            {
                System.Windows.Automation.Condition condition = null;
                int          result       = 1;
                int          num2         = 1;
                XmlAttribute xmlAttribute = UIAHelperMethods.GetXmlAttribute(control, "StartFromDesktop");
                if ((xmlAttribute != null) && (xmlAttribute.Value != null))
                {
                    bool flag = true;
                    if (xmlAttribute.Value == flag.ToString())
                    {
                        rootAutomationElement = AutomationElement.RootElement;
                    }
                }
                XmlNode xnPropCondition = control.SelectSingleNode("UIObject");
                if (xnPropCondition == null)
                {
                    return(rootAutomationElement);
                }
                do
                {
                    XmlAttribute attribute2 = UIAHelperMethods.GetXmlAttribute(xnPropCondition, "MatchCount");
                    if ((attribute2 != null) && (attribute2.Value != null))
                    {
                        int.TryParse(attribute2.Value, out result);
                    }
                    condition = this.BuildSearchCondition(xnPropCondition);
                    if (result == 1)
                    {
                        rootAutomationElement = rootAutomationElement.FindFirst(TreeScope.Children, condition);
                    }
                    else
                    {
                        AutomationElementCollection elements = rootAutomationElement.FindAll(TreeScope.Children, condition);
                        if ((result <= elements.Count) && (result > 0))
                        {
                            rootAutomationElement = elements[result - 1];
                        }
                        else
                        {
                            throw new DataDrivenAdapterException(OperationType.FindControl, controlName, "DDA0400_UNABLE_TO_FIND_CONTROL_ON_UI" + string.Format(CultureInfo.CurrentUICulture, "FIND_ERROR_LEVEL", new object[] { num2.ToString(CultureInfo.InvariantCulture) }));
                        }
                    }
                    if (rootAutomationElement == null)
                    {
                        throw new DataDrivenAdapterException(OperationType.FindControl, controlName, "DDA0400_UNABLE_TO_FIND_CONTROL_ON_UI" + string.Format(CultureInfo.CurrentUICulture, "FIND_ERROR_LEVEL", new object[] { num2.ToString(CultureInfo.InvariantCulture) }));
                    }
                    xnPropCondition = xnPropCondition.SelectSingleNode("UIObject");
                    num2++;
                }while (xnPropCondition != null);
            }
            return(rootAutomationElement);
        }
Ejemplo n.º 2
0
        private System.Windows.Automation.Condition BuildPropertyCondition(XmlNode xnPropCondition)
        {
            System.Windows.Automation.Condition condition = null;
            PropertyConditionFlags none = PropertyConditionFlags.None;
            string str = string.Empty;

            if (xnPropCondition.InnerText == null)
            {
                return(condition);
            }
            str = UIAHelperMethods.GetXmlAttribute(xnPropCondition, "Name").Value;
            Type type = AutomationPropReturnTypes[str];

            if (type.Equals(typeof(string)))
            {
                none = PropertyConditionFlags.IgnoreCase;
            }
            return(new PropertyCondition(AutomationProperties[str], this.ConvertStringtoObject(xnPropCondition.InnerText, AutomationPropReturnTypes[str]), none));
        }