Exemple #1
0
 protected override void Execute(CodeActivityContext context)
 {
     try
     {
         Int32     _HighlightTime = GetValueOrDefault(context, HighlightTime, 1);
         Color     _Value         = GetValueOrDefault(context, Value, Color.Red);
         var       selStr         = Selector.Get(context);
         UiElement element        = GetValueOrDefault(context, this.Element, null);
         if (element == null && selStr != null)
         {
             element = UiElement.FromSelector(selStr);
         }
         if (element != null)
         {
             element.DrawHighlight(_Value, TimeSpan.FromSeconds(_HighlightTime), true);
             Thread.Sleep(_HighlightTime * 1);
         }
         else
         {
             UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
         }
     }
     catch (Exception e)
     {
         SharedObject.Instance.Output(SharedObject.enOutputType.Error, "UI元素设置高亮失败", e.Message);
         if (ContinueOnError.Get(context))
         {
         }
         else
         {
             throw;
         }
     }
 }
Exemple #2
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = Common.GetValueOrDefault(context, this.DelayAfter, 300);
            Int32 _delayBefore = Common.GetValueOrDefault(context, this.DelayBefore, 300);

            Thread.Sleep(_delayBefore);
            try
            {
                // Prioritize to use the AutomationId or Name property to get faster.
                var nativeElement = UIAutomationCommon.GetNativeElement(context, WindowTitle, AutomationId, Name);
                if (nativeElement != null)
                {
                    UIAutomationCommon.MoveOnNativeElement(nativeElement);
                    Thread.Sleep(_delayAfter);
                    return;
                }

                var       selStr  = Selector.Get(context);
                UiElement element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                //Int32 pointX = 0;
                //Int32 pointY = 0;
                //if (usePoint)
                //{
                //    pointX = offsetX.Get(context);
                //    pointY = offsetY.Get(context);
                //}
                //else
                //{
                //    if (element != null)
                //    {
                //        pointX = element.GetClickablePoint().X;
                //        pointY = element.GetClickablePoint().Y;
                //        element.SetForeground();
                //    }
                //    else
                //    {
                //        UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, "查找不到元素");
                //        return;
                //    }
                //}
                var point = UIAutomationCommon.GetPoint(context, usePoint, offsetX, offsetY, element);
                if (point.X == -1 && point.Y == -1)
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                    return;
                }

                UiElement.MouseMoveTo(point);
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, e.Message);
            }
        }
Exemple #3
0
 private void DoSendKeys(CodeActivityContext context, List <string> strList)
 {
     foreach (string _strValue in strList)
     {
         string strValue = _strValue;
         if (strValue.Contains("[(") && strValue.Contains(")]"))
         {
             strValue = strValue.Replace("[(", "");
             strValue = strValue.Replace(")]", "");
             Thread.Sleep(100);
             if (Common.DealVirtualKeyPress(strValue.ToUpper()))
             {
                 Common.DealVirtualKeyRelease(strValue.ToUpper());
             }
             else
             {
                 UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, "找不到键值");
                 return;
             }
         }
         else if (strValue != null && strValue != "")
         {
             Thread.Sleep(100);
             SendKeys.SendWait(strValue);
         }
     }
 }
Exemple #4
0
        protected override void Execute(CodeActivityContext context)
        {
            string buff = "";

            try
            {
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                if (element != null)
                {
                    if (element.IsNativeObjectAutomationElement)
                    {
                        var nativieObject = element.NativeObject as AutomationElement;
                        var comboBox      = nativieObject.AsTextBox();
                        buff = comboBox.Text;
                        if (Value != null)
                        {
                            Value.Set(context, buff);
                        }
                    }
                }
                else
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                }
            }
            //catch(Exception)
            //{
            //    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "PatternNotSupportedException");
            //}
            //catch (FlaUI.Core.Exceptions.MethodNotSupportedException)
            //{
            //    DataGridView gridView = element.AsDataGridView();
            //    AutomationElement[] child = gridView.FindAllChildren();
            //    for (int i = 0; i < child.Length; i++)
            //    {
            //        string nameStr = child[i].Name;
            //        buff += nameStr;
            //    }
            //    if (Value != null)
            //        Value.Set(context, buff);
            //}
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "获取UI元素文本失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #5
0
        protected override void Execute(CodeActivityContext context)
        {
            string text         = Text.Get(context);
            Int32  _delayAfter  = GetValueOrDefault(context, this.DelayAfter, 300);
            Int32  _delayBefore = GetValueOrDefault(context, this.DelayBefore, 300);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                if (element != null)
                {
                    if (element.IsNativeObjectAutomationElement)
                    {
                        if (element.IsNativeObjectAutomationElement)
                        {
                            var nativieObject = element.NativeObject as AutomationElement;
                            var textbox       = nativieObject.AsTextBox();
                            if (!textbox.IsReadOnly)
                            {
                                textbox.Text = text;
                            }
                            else
                            {
                                SharedObject.Instance.Output(SharedObject.enOutputType.Error, Localize.LocalizedResources.GetString("msgErrorOccurred"), "该编辑框无法设置值");
                            }
                        }
                    }
                    else
                    {
                        UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, "非Window元素");
                    }
                }
                else
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                }
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "设置UI元素文本失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            string itemName     = Item.Get(context);
            Int32  _delayAfter  = GetValueOrDefault(context, this.DelayAfter, 300);
            Int32  _delayBefore = GetValueOrDefault(context, this.DelayBefore, 300);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                if (element != null)
                {
                    if (element.IsNativeObjectAutomationElement)
                    {
                        var nativieObject = element.NativeObject as AutomationElement;
                        var comboBox      = nativieObject.AsComboBox();
                        var comboItem     = comboBox.Select(itemName);
                        if (comboItem.Text != itemName)
                        {
                            var lbox     = nativieObject.AsListBox();
                            var listItem = lbox.Select(itemName);
                            if (listItem.Text != itemName)
                            {
                                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "SelectItem失败,请检查UI元素!");
                            }
                        }
                    }
                    else
                    {
                        UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, "非Window元素");
                    }
                }
                else
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                }
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "选取组合框或列表框项目失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = Common.GetValueOrDefault(context, this.DelayAfter, 300);
            Int32 _delayBefore = Common.GetValueOrDefault(context, this.DelayBefore, 300);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                //Int32 pointX = 0;
                //Int32 pointY = 0;
                //if (usePoint)
                //{
                //    pointX = offsetX.Get(context);
                //    pointY = offsetY.Get(context);
                //}
                //else
                //{
                //    if (element != null)
                //    {
                //        pointX = element.GetClickablePoint().X;
                //        pointY = element.GetClickablePoint().Y;
                //        element.SetForeground();
                //    }
                //}
                var point = UIAutomationCommon.GetPoint(context, usePoint, offsetX, offsetY, element);
                if (point.X == -1 && point.Y == -1)
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                    return;
                }
                if (isRunClick)
                {
                    UiElement.MouseMoveTo(point);
                    UiElement.MouseAction((Plugins.Shared.Library.UiAutomation.ClickType)ClickType, (Plugins.Shared.Library.UiAutomation.MouseButton)MouseButton);
                }
                DealBaseKeyBordPress();
                if (Common.DealVirtualKeyPress(SelectedKey.ToUpper()))
                {
                    Common.DealVirtualKeyRelease(SelectedKey.ToUpper());
                }
                DealBaseKeyBordRelease();
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, e.Message);
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            string attribute_str   = Attribute.Get(context);
            string attribute_value = Value.Get(context);

            try
            {
                Int32 _timeout = TimeoutMS.Get(context);
                Thread.Sleep(_timeout);
                latch = new CountdownEvent(1);
                Thread td = new Thread(() =>
                {
                    if (Selector.Expression == null)
                    {
                        //ActiveElement处理
                    }
                    else
                    {
                        var selStr        = Selector.Get(context);
                        UiElement element = GetValueOrDefault(context, this.Element, null);
                        if (element == null && selStr != null)
                        {
                            element = UiElement.FromSelector(selStr);
                        }
                        if (element != null)
                        {
                            element.SetForeground();
                            mshtml.IHTMLDocument2 currDoc      = null;
                            SHDocVw.InternetExplorer ieBrowser = GetIEFromHWndClass.GetIEFromHWnd((int)element.WindowHandle, out currDoc);
                            mshtml.IHTMLElement currEle        = GetIEFromHWndClass.GetEleFromDoc(
                                element.GetClickablePoint(), (int)element.WindowHandle, currDoc);
                            currEle.setAttribute(attribute_str, attribute_value);
                        }
                        else
                        {
                            UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                        }
                    }
                    refreshData(latch);
                });
                td.TrySetApartmentState(ApartmentState.STA);
                td.IsBackground = true;
                td.Start();
                latch.Wait();
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "出现异常", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = GetValueOrDefault(context, this.DelayAfter, 3000);
            Int32 _delayBefore = GetValueOrDefault(context, this.DelayBefore, 2000);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                Int32 pointX = 0;
                Int32 pointY = 0;
                if (element != null)
                {
                    pointX = element.GetClickablePoint().X;
                    pointY = element.GetClickablePoint().Y;
                    element.SetForeground();
                    element.Focus();
                }
                else
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                }
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "设置键盘焦点失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #10
0
        private void UiElement_OnSelected(UiElement uiElement)
        {
            // Get the window title to identify the element from Name/AutomationId
            string title = UIAutomationCommon.GetRootWindowTitle(UiCommon.GetForegroundWindow());

            setPropertyValue("WindowTitle", new InArgument <string>(title));

            var screenshotsPath = uiElement.CaptureInformativeScreenshotToFile();

            setPropertyValue("SourceImgPath", screenshotsPath);
            setPropertyValue("AutomationId", new InArgument <string>(uiElement.AutomationId));
            setPropertyValue("Name", new InArgument <string>(uiElement.Name));
            setPropertyValue("Selector", new InArgument <string>(uiElement.Selector));
            grid1.Visibility = System.Windows.Visibility.Hidden;
            setPropertyValue("visibility", System.Windows.Visibility.Visible);
            InArgument <Int32> _offsetX = uiElement.GetClickablePoint().X;
            InArgument <Int32> _offsetY = uiElement.GetClickablePoint().Y;

            setPropertyValue("offsetX", _offsetX);
            setPropertyValue("offsetY", _offsetY);
            string displayName = getPropertyValue("_DisplayName") + " \"" + uiElement.ProcessName + " " + uiElement.Name + "\"";

            setPropertyValue("DisplayName", displayName);
            InArgument <Int32> _Left = uiElement.BoundingRectangle.Left;

            setPropertyValue("Left", _Left);
            InArgument <Int32> _Right = uiElement.BoundingRectangle.Right;

            setPropertyValue("Right", _Right);
            InArgument <Int32> _Top = uiElement.BoundingRectangle.Top;

            setPropertyValue("Top", _Top);
            InArgument <Int32> _Bottom = uiElement.BoundingRectangle.Bottom;

            setPropertyValue("Bottom", _Bottom);
        }
Exemple #11
0
        private void UiElement_OnSelected(UiElement uiElement)
        {
            // Get the window title to identify the element from Name/AutomationId
            string title = UIAutomationCommon.GetRootWindowTitle(UiCommon.GetForegroundWindow());

            setPropertyValue("WindowTitle", new InArgument <string>(title));

            var screenshotsPath = uiElement.CaptureInformativeScreenshotToFile();

            navigateTextBlock.Visibility = System.Windows.Visibility.Hidden;
            setPropertyValue("SourceImgPath", screenshotsPath);
            setPropertyValue("AutomationId", new InArgument <string>(uiElement.AutomationId));
            setPropertyValue("Name", new InArgument <string>(uiElement.Name));
            setPropertyValue("Selector", new InArgument <string>(uiElement.Selector));
            setPropertyValue("visibility", System.Windows.Visibility.Visible);
            InArgument <Int32> _offsetX = uiElement.GetClickablePoint().X;
            InArgument <Int32> _offsetY = uiElement.GetClickablePoint().Y;

            setPropertyValue("offsetX", _offsetX);
            setPropertyValue("offsetY", _offsetY);
            string displayName = getPropertyValue("DisplayName") + " \"" + uiElement.ProcessName + " " + uiElement.Name + "\"";

            setPropertyValue("DisplayName", displayName);
        }
Exemple #12
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = Common.GetValueOrDefault(context, this.DelayAfter, 300);
            Int32 _delayBefore = Common.GetValueOrDefault(context, this.DelayBefore, 300);

            try
            {
                Thread.Sleep(_delayBefore);
                SecureString secureText = SecureText.Get(context);
                IntPtr       inP        = Marshal.SecureStringToBSTR(secureText);//inP为secureStr的句柄
                string       text       = Marshal.PtrToStringBSTR(inP);
                var          selStr     = Selector.Get(context);
                UiElement    element    = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                //Int32 pointX = 0;
                //Int32 pointY = 0;
                //if (usePoint)
                //{
                //    pointX = offsetX.Get(context);
                //    pointY = offsetY.Get(context);
                //}
                //else
                //{
                //    if (element != null)
                //    {
                //        pointX = element.GetClickablePoint().X;
                //        pointY = element.GetClickablePoint().Y;
                //        element.SetForeground();
                //    }
                //    else
                //    {
                //        UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, "查找不到元素");
                //        return;
                //    }
                //}
                var point = UIAutomationCommon.GetPoint(context, usePoint, offsetX, offsetY, element);
                if (point.X == -1 && point.Y == -1)
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                    return;
                }
                /*执行鼠标点击事件*/
                if (isRunClick)
                {
                    UiElement.MouseMoveTo(point);
                    UiElement.MouseAction((Plugins.Shared.Library.UiAutomation.ClickType)ClickType, (Plugins.Shared.Library.UiAutomation.MouseButton)MouseButton);
                }
                else if (true)
                {
                }
                else
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, "找不到键值");
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "发送安全文本执行过程出错", e.Message);
            }
        }
Exemple #13
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = Common.GetValueOrDefault(context, this.DelayAfter, 300);
            Int32 _delayBefore = Common.GetValueOrDefault(context, this.DelayBefore, 300);

            Thread.Sleep(_delayBefore);
            try
            {
                // Prioritize to use the AutomationId or Name property to get faster.
                var nativeElement = UIAutomationCommon.GetNativeElement(context, WindowTitle, AutomationId, Name);
                if (nativeElement != null)
                {
                    int moveX = 0, moveY = 0;
                    if (clickOffsetPoint)
                    {
                        moveX = moveOffsetX.Get(context);
                        moveY = moveOffsetY.Get(context);
                    }
                    UIAutomationCommon.ClickNativeElement(nativeElement, moveX, moveY);
                    Thread.Sleep(_delayAfter);
                    return;
                }

                var selStr  = Selector.Get(context);
                var element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                var point = UIAutomationCommon.GetPoint(context, usePoint, offsetX, offsetY, element);
                if (point.X == -1 && point.Y == -1)
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                    return;
                }

                if (KeyModifiers != null)
                {
                    string[] sArray = KeyModifiers.Split(',');
                    foreach (string i in sArray)
                    {
                        Common.DealKeyBordPress(i);
                    }
                }
                UiElement.MouseMoveTo(point);
                UiElement.MouseAction((Plugins.Shared.Library.UiAutomation.ClickType)ClickType, (Plugins.Shared.Library.UiAutomation.MouseButton)MouseButton);
                if (KeyModifiers != null)
                {
                    string[] sArray = KeyModifiers.Split(',');
                    foreach (string i in sArray)
                    {
                        Common.DealKeyBordRelease(i);
                    }
                }
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, e.Message);
            }
        }
Exemple #14
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = Common.GetValueOrDefault(context, this.DelayAfter, 300);
            Int32 _delayBefore = Common.GetValueOrDefault(context, this.DelayBefore, 300);

            Thread.Sleep(_delayBefore);

            try
            {
                string        expValue = Text.Get(context);
                List <string> strList  = new List <string>();
                ParseStringToList(ref expValue, ref strList);

                // Prioritize to use the AutomationId or Name property to get faster.
                var nativeElement = UIAutomationCommon.GetNativeElement(context, WindowTitle, AutomationId, Name);
                if (nativeElement != null)
                {
                    if (moveOffsetClick)
                    {
                        int moveX = moveOffsetX.Get(context);
                        int moveY = moveOffsetY.Get(context);
                        UIAutomationCommon.MoveOnNativeElement(nativeElement, moveX, moveY);
                        FlaUI.Core.Input.Mouse.Click();
                    }
                    DoSendKeys(context, strList);
                    Thread.Sleep(_delayAfter);
                    return;
                }

                var       selStr  = Selector.Get(context);
                UiElement element = Common.GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }

                //Int32 pointX = 0;
                //Int32 pointY = 0;
                //if (usePoint)
                //{
                //    pointX = offsetX.Get(context);
                //    pointY = offsetY.Get(context);
                //}
                //else
                //{
                //    if (element != null)
                //    {
                //        pointX = element.GetClickablePoint().X;
                //        pointY = element.GetClickablePoint().Y;
                //        //element.SetForeground();//输入框置前窗口会导致焦点跳出,去除
                //    }
                //}
                var point = UIAutomationCommon.GetPoint(context, usePoint, offsetX, offsetY, element, false);
                if (point.X == -1 && point.Y == -1)
                {
                    UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                    return;
                }
                if (isRunClick)
                {
                    UiElement.MouseMoveTo(point);
                    UiElement.MouseAction((Plugins.Shared.Library.UiAutomation.ClickType)ClickType, (Plugins.Shared.Library.UiAutomation.MouseButton)MouseButton);
                }
                DoSendKeys(context, strList);
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, e.Message);
            }
        }