コード例 #1
0
        public static JavaElement[] EnumRoots(WindowsAccessBridgeInterop.AccessibleJvm jvm)
        {
            var results  = new List <JavaElement>();
            var children = jvm.GetChildren();

            if (children != null && children.Count() > 0)
            {
                var  firstac = children.First() as WindowsAccessBridgeInterop.AccessibleContextNode;
                var  hwnd    = jvm.AccessBridge.Functions.GetHWNDFromAccessibleContext(jvm.JvmId, firstac.AccessibleContextHandle);
                RECT rect    = new RECT();
                GetWindowRect(hwnd, ref rect);

                int x   = rect.Left + ((rect.Right - rect.Left) / 2);
                int y   = rect.Top + ((rect.Bottom - rect.Top) / 2);
                var res = firstac.GetNodePathAtUsingAccessBridge(new System.Drawing.Point(x, y));
                if (res != null)
                {
                    var Root   = new JavaElement(res.Root);
                    var Parent = Root;
                    while (Parent.Parent != null)
                    {
                        Parent = Parent.Parent;
                    }
                    if (!results.Contains(Parent))
                    {
                        results.Add(Parent);
                    }
                }


                //for(var x= rect.Left; x < rect.Right; x += 10)
                //{
                //    for (var y = rect.Top; y < rect.Bottom; y += 10)
                //    {
                //        var res = firstac.GetNodePathAtUsingAccessBridge(new System.Drawing.Point(x, y));
                //        if (res != null)
                //        {
                //            var Root = new JavaElement(res.Root);
                //            var Parent = Root;
                //            while (Parent.Parent != null) Parent = Parent.Parent;
                //            if(!results.Contains(Parent)) results.Add(Parent);
                //        }
                //    }
                //}
            }


            return(results.ToArray());
        }
コード例 #2
0
ファイル: JavaSelector.cs プロジェクト: vantk85/openrpa
        private static JavaElement[] GetElementsWithuiSelector(WindowsAccessBridgeInterop.AccessibleJvm jvm, JavaSelector selector, IElement fromElement, int maxresults)
        {
            JavaElement[] result       = null;
            JavaElement   _fromElement = fromElement as JavaElement;
            var           selectors    = selector.Where(x => x.Enabled == true && x.Selector == null).ToList();
            var           current      = new List <JavaElement>();
            JavaElement   startfrom    = null;

            if (_fromElement != null)
            {
                startfrom = _fromElement;
            }
            if (startfrom == null)
            {
                startfrom = new JavaElement(jvm);
            }
            current.Add(startfrom);
            var _children = jvm.GetChildren();

            foreach (var e in Plugin.EnumRoots(jvm))
            {
                current.Add(e);
            }
            for (var i = 0; i < selectors.Count; i++)
            {
                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                var s = new JavaSelectorItem(selectors[i]);
                Log.Selector(string.Format("OpenRPA.Java::GetElementsWithuiSelector::Find for selector {0} {1}", i, s.ToString()));
                var elements = new List <JavaElement>();
                elements.AddRange(current);
                current.Clear();
                foreach (var _element in elements)
                {
                    result = ((JavaSelectorItem)s).matches(_element);
                    current.AddRange(result);
                }
                if (current.Count == 0)
                {
                    // TODO: Figure out, why this is needed when working with Java Menu's
                    foreach (var _e in elements)
                    {
                        if (s.Match(_e))
                        {
                            current.Add(_e);
                        }
                    }
                }
                if (i == (selectors.Count - 1))
                {
                    result = current.ToArray();
                }
                if (current.Count == 0 && Config.local.log_selector)
                {
                    var _c      = new JavaSelectorItem(selectors[i]);
                    var message = "needed to find " + Environment.NewLine + _c.ToString() + Environment.NewLine + "but found only: " + Environment.NewLine;
                    foreach (var element in elements)
                    {
                        var children = element.Children;
                        foreach (var c in children)
                        {
                            try
                            {
                                message += c.ToString() + Environment.NewLine;
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    Log.Selector(message);
                    return(new JavaElement[] { });
                }
                Log.Selector(string.Format("OpenRPA.Java::GetElement::found {1} for selector {2} in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count(), i));
            }
            if (result == null)
            {
                return new JavaElement[] { }
            }
            ;
            return(result);
        }