Пример #1
0
        public static treeelement[] _GetRootElements(Selector anchor)
        {
            var browser = Browser.GetBrowser();

            if (browser == null)
            {
                Log.Warning("Failed locating an Internet Explore instance");
                return(new treeelement[] { });
            }
            if (anchor != null)
            {
                IESelector ieselector = anchor as IESelector;
                if (ieselector == null)
                {
                    ieselector = new IESelector(anchor.ToString());
                }
                var elements = IESelector.GetElementsWithuiSelector(ieselector, null, 5);
                var result   = new List <treeelement>();
                foreach (var _ele in elements)
                {
                    var e = new IETreeElement(null, true, _ele);
                    result.Add(e);
                }
                return(result.ToArray());
            }
            else
            {
                var e = new IETreeElement(null, true, new IEElement(browser, browser.Document.documentElement));
                return(new treeelement[] { e });
            }
        }
Пример #2
0
        protected override void Execute(NativeActivityContext context)
        {
            var selector = Selector.Get(context);
            var sel      = new IESelector(selector);
            var timeout  = TimeSpan.FromSeconds(3);
            var from     = From.Get(context);

            IEElement[] elements = { };
            var         sw       = new Stopwatch();

            sw.Start();
            do
            {
                elements = IESelector.GetElementsWithuiSelector(sel, from);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            context.SetValue(Elements, elements);
            IEnumerator <IEElement> _enum = elements.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
            else
            {
                throw new Interfaces.ElementNotFoundException("Failed locating item");
            }
        }
Пример #3
0
        public IElement[] GetElementsWithSelector(Selector selector, IElement fromElement = null, int maxresults = 1)
        {
            if (!(selector is IESelector ieselector))
            {
                ieselector = new IESelector(selector.ToString());
            }
            var result = IESelector.GetElementsWithuiSelector(ieselector, fromElement, maxresults);

            return(result);
        }
Пример #4
0
        protected override void Execute(NativeActivityContext context)
        {
            var selector = Selector.Get(context);

            selector = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selector, context.DataContext);
            var sel        = new IESelector(selector);
            var timeout    = Timeout.Get(context);
            var from       = From.Get(context);
            var maxresults = MaxResults.Get(context);

            if (maxresults < 1)
            {
                maxresults = 1;
            }
            IEElement[] elements = { };

            if (WaitForReady.Get(context))
            {
                var browser             = Browser.GetBrowser();
                MSHTML.HTMLDocument doc = browser.Document;
                var sw2 = new Stopwatch();
                sw2.Start();
                while (sw2.Elapsed < timeout && doc.readyState != "complete" && doc.readyState != "interactive")
                {
                    // Log.Debug("pending complete, readyState: " + doc.readyState);
                    System.Threading.Thread.Sleep(100);
                }
            }

            var sw = new Stopwatch();

            sw.Start();
            do
            {
                elements = IESelector.GetElementsWithuiSelector(sel, from);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }
            context.SetValue(Elements, elements);
            IEnumerator <IEElement> _enum = elements.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
            else
            {
                throw new Interfaces.ElementNotFoundException("Failed locating item");
            }
        }
Пример #5
0
        private async void Highlight_Click(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresults     = ModelItem.GetValue <int>("MaxResults");
            var    selector       = new IESelector(SelectorString);
            var    elements       = IESelector.GetElementsWithuiSelector(selector, null, maxresults);

            foreach (var ele in elements)
            {
                await ele.Highlight(false, System.Drawing.Color.Red, TimeSpan.FromSeconds(1));
            }
        }
Пример #6
0
        private void Highlight_Click(object sender, RoutedEventArgs e)
        {
            ModelItem  loadFrom = ModelItem.Parent;
            string     loadFromSelectorString = "";
            IESelector anchor = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Selector").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    anchor = new IESelector(loadFromSelectorString);
                    break;
                }
                loadFrom = loadFrom.Parent;
            }

            HighlightImage = IEExtensions.GetImageSourceFromResource(".x.png");
            NotifyPropertyChanged("HighlightImage");

            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresults     = ModelItem.GetValue <int>("MaxResults");
            var    selector       = new IESelector(SelectorString);
            var    elements       = new List <IEElement>();

            if (anchor != null)
            {
                var _base = IESelector.GetElementsWithuiSelector(anchor, null, 10);
                foreach (var _e in _base)
                {
                    var res = IESelector.GetElementsWithuiSelector(selector, _e, maxresults);
                    elements.AddRange(res);
                }
            }
            else
            {
                var res = IESelector.GetElementsWithuiSelector(selector, null, maxresults);
                elements.AddRange(res);
            }

            if (elements.Count() > 0)
            {
                HighlightImage = IEExtensions.GetImageSourceFromResource("check.png");
                NotifyPropertyChanged("HighlightImage");
            }
            foreach (var ele in elements)
            {
                ele.Highlight(false, System.Drawing.Color.Red, TimeSpan.FromSeconds(1));
            }
        }
Пример #7
0
        protected override void Execute(NativeActivityContext context)
        {
            var selector = Selector.Get(context);

            selector = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selector, context.DataContext);
            var sel        = new IESelector(selector);
            var timeout    = Timeout.Get(context);
            var from       = From.Get(context);
            var maxresults = MaxResults.Get(context);

            if (maxresults < 1)
            {
                maxresults = 1;
            }
            IEElement[] elements = { };
            var         sw       = new Stopwatch();

            sw.Start();
            do
            {
                elements = IESelector.GetElementsWithuiSelector(sel, from);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }
            context.SetValue(Elements, elements);
            IEnumerator <IEElement> _enum = elements.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
            else
            {
                throw new Interfaces.ElementNotFoundException("Failed locating item");
            }
        }
Пример #8
0
 public override IElement[] GetElements(IElement fromElement = null, int maxresults = 1)
 {
     return(IESelector.GetElementsWithuiSelector(this, fromElement, maxresults));
 }
Пример #9
0
        protected override void StartLoop(NativeActivityContext context)
        {
            var selector = Selector.Get(context);

            selector = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selector, context.DataContext);
            var sel     = new IESelector(selector);
            var timeout = Timeout.Get(context);

            if (Timeout == null || Timeout.Expression == null)
            {
                timeout = TimeSpan.FromSeconds(3);
            }
            var from       = From.Get(context);
            var maxresults = MaxResults.Get(context);
            var minresults = MinResults.Get(context);

            if (maxresults < 1)
            {
                maxresults = 1;
            }
            IEElement[] elements = { };
            if (timeout.Minutes > 5 || timeout.Hours > 1)
            {
                Activity _Activity = null;
                try
                {
                    var strProperty = context.GetType().GetProperty("Activity", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    var strGetter   = strProperty.GetGetMethod(nonPublic: true);
                    _Activity = (Activity)strGetter.Invoke(context, null);
                }
                catch (Exception)
                {
                }
                if (_Activity != null)
                {
                    Log.Warning("Timeout for Activity " + _Activity.Id + " is above 5 minutes, was this the intention ? calculated value " + timeout.ToString());
                }
                else
                {
                    Log.Warning("Timeout for on of your IE.GetElements is above 5 minutes, was this the intention ? calculated value " + timeout.ToString());
                }
            }

            if (WaitForReady.Get(context))
            {
                var browser             = Browser.GetBrowser(false);
                MSHTML.HTMLDocument doc = browser.Document;
                var sw2 = new Stopwatch();
                sw2.Start();
                string readyState = "";
                while (sw2.Elapsed < timeout && readyState != "complete" && readyState != "interactive")
                {
                    try
                    {
                        readyState = doc.readyState;
                    }
                    catch (Exception)
                    {
                        browser = Browser.GetBrowser(true);
                    }
                    // Log.Debug("pending complete, readyState: " + doc.readyState);
                    System.Threading.Thread.Sleep(100);
                }
            }

            var sw = new Stopwatch();

            sw.Start();
            do
            {
                elements = IESelector.GetElementsWithuiSelector(sel, from, maxresults);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }
            if (elements.Length < minresults)
            {
                Log.Selector(string.Format("Windows.GetElement::Failed locating " + minresults + " item(s) {0:mm\\:ss\\.fff}", sw.Elapsed));
                throw new ElementNotFoundException("Failed locating " + minresults + " item(s)");
            }

            context.SetValue(Elements, elements);
            IEnumerator <IEElement> _enum = elements.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                IncIndex(context);
                SetTotal(context, elements.Length);
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }
Пример #10
0
        protected override void StartLoop(NativeActivityContext context)
        {
            var selector = Selector.Get(context);

            selector = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selector, context.DataContext);
            var sel        = new IESelector(selector);
            var timeout    = Timeout.Get(context);
            var from       = From.Get(context);
            var maxresults = MaxResults.Get(context);
            var minresults = MinResults.Get(context);

            if (maxresults < 1)
            {
                maxresults = 1;
            }
            IEElement[] elements = { };

            if (WaitForReady.Get(context))
            {
                var browser             = Browser.GetBrowser(false);
                MSHTML.HTMLDocument doc = browser.Document;
                var sw2 = new Stopwatch();
                sw2.Start();
                string readyState = "";
                while (sw2.Elapsed < timeout && readyState != "complete" && readyState != "interactive")
                {
                    try
                    {
                        readyState = doc.readyState;
                    }
                    catch (Exception)
                    {
                        browser = Browser.GetBrowser(true);
                    }
                    // Log.Debug("pending complete, readyState: " + doc.readyState);
                    System.Threading.Thread.Sleep(100);
                }
            }

            var sw = new Stopwatch();

            sw.Start();
            do
            {
                elements = IESelector.GetElementsWithuiSelector(sel, from, maxresults);
            } while (elements.Count() == 0 && sw.Elapsed < timeout);
            if (elements.Count() > maxresults)
            {
                elements = elements.Take(maxresults).ToArray();
            }
            if (elements.Length < minresults)
            {
                Log.Selector(string.Format("Windows.GetElement::Failed locating " + minresults + " item(s) {0:mm\\:ss\\.fff}", sw.Elapsed));
                throw new ElementNotFoundException("Failed locating " + minresults + " item(s)");
            }

            context.SetValue(Elements, elements);
            IEnumerator <IEElement> _enum = elements.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }