예제 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                string attrName    = AttrName.Get(context);
                object attrValue   = AttrValue.Get(context);
                Int32  timeOut     = TimeOut.Get(context);
                bool   isFoundFlag = false;

                UiElement         element = Common.GetValueOrDefault(context, this.Element, null);
                AutomationElement autoEle = element.NativeObject as AutomationElement;
                FrameworkAutomationElementBase baseFrame = autoEle.FrameworkAutomationElement;
                PropertyId[] ids       = autoEle.GetSupportedPropertiesDirect();
                PropertyId   currentId = null;
                for (int i = 0; i < ids.Length; i++)
                {
                    if (String.Equals(ids[i].Name, attrName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        currentId = ids[i];
                        break;
                    }
                }
                for (int i = 0; i < timeOut / 1000; i++)
                {
                    if (attrValue == baseFrame.GetPropertyValue(currentId))
                    {
                        isFoundFlag = true;
                        break;
                    }
                    Thread.Sleep(1000);
                }
                if (!isFoundFlag && !ContinueOnError.Get(context))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "相应元素的属性值未匹配,获取属性失败");
                    throw new Exception("获取属性失败,过程中断");
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "等待获取元素属性过程出错", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return;
                }
                else
                {
                    throw e;
                }
            }
        }
예제 #2
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                var    selStr    = Selector.Get(context);
                object attrValue = null;
                string attrName  = AttrName.Get(context);

                UiElement element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                AutomationElement autoEle = element.NativeObject as AutomationElement;
                FrameworkAutomationElementBase baseFrame = autoEle.FrameworkAutomationElement;
                PropertyId[] ids = autoEle.GetSupportedPropertiesDirect();
                for (int i = 0; i < ids.Length; i++)
                {
                    if (String.Equals(ids[i].Name, attrName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        attrValue = baseFrame.GetPropertyValue(ids[i]);
                        break;
                    }
                }
                if (attrValue == null)
                {
                    Result.Set(context, "");
                }
                else
                {
                    Result.Set(context, attrValue);
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "获取元素属性失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return;
                }
                else
                {
                    throw e;
                }
            }
        }