Exemple #1
0
        /// <summary>
        /// 若element是JAVA窗口,则里面的元素要按照JAVA节点方式获取
        /// </summary>
        /// <param name="element"></param>
        /// <param name="screenPoint"></param>
        /// <returns></returns>
        private bool inspectJavaUiNode(AutomationElement element, Point screenPoint)
        {
            if (element != null)
            {
                //判断是否是JAVA窗口
                var node = new UIAUiNode(element);
                if (JavaUiNode.accessBridge.Functions.IsJavaWindow(node.WindowHandle))
                {
                    //是JAVA窗口,内部节点按JAVA方式选择
                    Path <AccessibleNode> javaNodePath = JavaUiNode.EnumJvms().Select(javaNode => javaNode.GetNodePathAt(screenPoint)).Where(x => x != null).FirstOrDefault();
                    var currentJavaNode = javaNodePath == null ? null : javaNodePath.Leaf;
                    if (currentJavaNode == null)
                    {
                        return(false);
                    }

                    CurrentHighlightElement = new JavaUiNode(currentJavaNode);

                    var rect = currentJavaNode.GetScreenRectangle();
                    //计算鼠标点击时的相对元素的偏移,以供后期有必要时使用
                    CurrentHighlightElementRelativeClickPos = new Point(screenPoint.X - (int)rect?.Left, screenPoint.Y - (int)rect?.Top);

                    this.MoveRect((Rectangle)currentJavaNode.GetScreenRectangle());
                    return(true);
                }
            }
            //Console.WriteLine("return false ");
            return(false);
        }
Exemple #2
0
        public UiNode FindRelativeNode(int position, int offsetX, int offsetY)
        {
            UIAUiNode relativeNode = null;
            Rectangle rect = automationElement.BoundingRectangle;
            int       posX, posY;
            Point     point;

            switch (position)
            {
            case 0:         //中心位置偏移
                posX  = rect.Location.X + rect.Width / 2;
                posY  = rect.Location.Y + rect.Height / 2;
                point = new Point(posX + offsetX, posY + offsetY);
                break;

            case 1:         //左上角偏移
                posX  = rect.Location.X;
                posY  = rect.Location.Y;
                point = new Point(posX + offsetX, posY + offsetY);
                break;

            case 2:         //右上角偏移
                posX  = rect.Location.X + rect.Width;
                posY  = rect.Location.Y;
                point = new Point(posX + offsetX, posY + offsetY);
                break;

            case 3:         //左下角偏移
                posX  = rect.Location.X;
                posY  = rect.Location.Y + rect.Height;
                point = new Point(posX + offsetX, posY + offsetY);
                break;

            case 4:         //右下角偏移
                posX  = rect.Location.X + rect.Width;
                posY  = rect.Location.Y + rect.Height;
                point = new Point(posX + offsetX, posY + offsetY);
                break;

            default:        //默认中心偏移
                posX  = rect.Location.X + rect.Width / 2;
                posY  = rect.Location.Y + rect.Height / 2;
                point = new Point(posX + offsetX, posY + offsetY);
                break;
            }


            try
            {
                this.automationElement = UIAUiNode.UIAAutomation.FromPoint(point);
            }
            catch (Exception)
            {
                if (this.automationElement == null)
                {
                    IntPtr hWnd = UiCommon.WindowFromPoint(point);
                    if (hWnd != IntPtr.Zero)
                    {
                        this.automationElement = UIAUiNode.UIAAutomation.FromHandle(hWnd);
                    }
                }
            }
            relativeNode = new UIAUiNode(automationElement);
            return(relativeNode);
        }
Exemple #3
0
 public UIAUiNode(AutomationElement element, UIAUiNode parent = null)
 {
     this.automationElement = element;
     this.cachedParent      = parent;
 }