private void DoWaitForReady(string browser) { if (!string.IsNullOrEmpty(browser)) { NMHook.enumtabs(); if (browser == "chrome" && NMHook.CurrentChromeTab != null) { NMHook.WaitForTab(NMHook.CurrentChromeTab.id, browser, TimeSpan.FromSeconds(10)); } if (browser == "ff" && NMHook.CurrentFFTab != null) { NMHook.WaitForTab(NMHook.CurrentFFTab.id, browser, TimeSpan.FromSeconds(10)); } } }
protected override void Execute(NativeActivityContext context) { var selector = Selector.Get(context); selector = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selector, context.DataContext); var sel = new NMSelector(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; } NMElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); if (WaitForReady.Get(context)) { string browser = sel.browser; if (from != null) { browser = from.browser; } if (!string.IsNullOrEmpty(browser)) { NMHook.enumtabs(); if (browser == "chrome" && NMHook.CurrentChromeTab != null) { NMHook.WaitForTab(NMHook.CurrentChromeTab.id, browser, TimeSpan.FromSeconds(10)); } if (browser == "ff" && NMHook.CurrentFFTab != null) { NMHook.WaitForTab(NMHook.CurrentFFTab.id, browser, TimeSpan.FromSeconds(10)); } } } do { elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults); } while (elements.Count() == 0 && sw.Elapsed < timeout); if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } context.SetValue(Elements, elements); var lastelements = context.GetValue(_lastelements); if (lastelements == null) { lastelements = new NMElement[] { } } ; context.SetValue(_lastelements, elements); if ((elements.Length + lastelements.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)"); } IEnumerator <NMElement> _enum = elements.ToList().GetEnumerator(); bool more = _enum.MoveNext(); if (lastelements.Length == elements.Length && lastelements.Length > 0) { var eq = new Activities.NMEqualityComparer(); more = !System.Collections.StructuralComparisons.StructuralEqualityComparer.Equals(lastelements, elements); } if (more) { context.SetValue(_elements, _enum); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }