protected override void StartLoop(NativeActivityContext context) { if (Image == null) { new ArgumentException("Image is null"); } //var timeout = TimeSpan.FromSeconds(3); var timeout = Timeout.Get(context); if (Timeout == null || Timeout.Expression == null) { timeout = TimeSpan.FromSeconds(3); } var maxresults = MaxResults.Get(context); var processname = Processname.Get(context); var comparegray = CompareGray.Get(context); var threshold = Threshold.Get(context); var minresults = MinResults.Get(context); var from = From.Get(context); var limit = Limit.Get(context); if (maxresults < 1) { maxresults = 1; } if (threshold < 0.1) { threshold = 0.1; } if (threshold > 1) { threshold = 1; } ImageElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { elements = getBatch(minresults, maxresults, threshold, processname, timeout, comparegray, limit).ToArray(); } while (elements.Count() == 0 && sw.Elapsed < timeout); // Log.Debug(string.Format("OpenRPA.Image::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count())); context.SetValue(Elements, elements); IEnumerator <ImageElement> _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); } else if (elements.Count() < minresults) { throw new Interfaces.ElementNotFoundException("Failed locating item"); } }
protected override void Execute(NativeActivityContext context) { var selector = Selector.Get(context); var sel = new NMSelector(selector); var timeout = TimeSpan.FromSeconds(3); var from = From.Get(context); var maxresults = MaxResults.Get(context); NMElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { elements = NMSelector.GetElementsWithuiSelector(sel, from); } while (elements.Count() == 0 && sw.Elapsed < timeout); if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } context.SetValue(Elements, elements); IEnumerator <NMElement> _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"); } }
protected override void Execute(NativeActivityContext context) { var SelectorString = Selector.Get(context); SelectorString = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(SelectorString, context.DataContext); var sel = new JavaSelector(SelectorString); var timeout = TimeSpan.FromSeconds(3); var maxresults = MaxResults.Get(context); var from = From.Get(context); if (maxresults < 1) maxresults = 1; JavaElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { var selector = new JavaSelector(SelectorString); elements = JavaSelector.GetElementsWithuiSelector(selector, from, maxresults); } while (elements.Count() == 0 && sw.Elapsed < timeout); Log.Debug(string.Format("OpenRPA.Java::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count())); context.SetValue(Elements, elements); IEnumerator<JavaElement> _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"); } }
protected override void Execute(NativeActivityContext context) { UIElement[] elements = null; var selector = Selector.Get(context); var sel = new WindowsSelector(selector); var timeout = Timeout.Get(context); var maxresults = MaxResults.Get(context); var minresults = MinResults.Get(context); if (maxresults < 1) { maxresults = 1; } var sw = new Stopwatch(); var from = From.Get(context); sw.Start(); do { elements = OpenRPA.AutomationHelper.RunSTAThread <UIElement[]>(() => { try { return(WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults)); } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { Log.Error(ex, ""); } return(new UIElement[] { }); }, TimeSpan.FromMilliseconds(250)).Result; if (elements == null) { elements = new UIElement[] { }; } } while (elements != null && elements.Length == 0 && sw.Elapsed < timeout); if (elements.Length > 0) { // Get them again, we need the COM objects to be loaded in the UI thread elements = WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults); } context.SetValue(Elements, elements); if (elements.Count() < minresults) { throw new ElementNotFoundException("Failed locating " + minresults + " item(s)"); } IEnumerator <UIElement> _enum = elements.ToList().GetEnumerator(); context.SetValue(_elements, _enum); bool more = _enum.MoveNext(); if (more) { context.ScheduleAction <UIElement>(Body, _enum.Current, OnBodyComplete); } }
protected override void AfterExecute(NativeActivityContext context, object result) { var allelements = context.GetValue(_allelements); if (allelements == null) { allelements = new NMElement[] { } } ; var maxresults = MaxResults.Get(context); var minresults = MinResults.Get(context); NMElement[] elements = result as NMElement[]; if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } if ((elements.Length + allelements.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) { allelements = allelements.Concat(elements).ToArray(); var eq = new Activities.NMEqualityComparer(); allelements = allelements.Distinct(eq).ToArray(); //var allelementslength = allelements.Length; //Array.Resize(ref allelements, allelements.Length + elements.Length); //Array.Copy(elements, 0, allelements, allelementslength, elements.Length); } context.SetValue(_allelements, allelements); context.SetValue(Elements, allelements); Log.Selector("END:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); if (more) { context.SetValue(_elements, _enum); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }
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"); } }
protected override void StartLoop(NativeActivityContext context) { var SelectorString = Selector.Get(context); SelectorString = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(SelectorString, context.DataContext); var sel = new SAPSelector(SelectorString); var timeout = Timeout.Get(context); var maxresults = MaxResults.Get(context); var minresults = MinResults.Get(context); var flatternguitree = FlatternGuiTree.Get(context); //var from = From.Get(context); SAPElement from = null; if (maxresults < 1) { maxresults = 1; } SAPElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { var selector = new SAPSelector(SelectorString); elements = SAPSelector.GetElementsWithuiSelector(selector, from, 0, maxresults, flatternguitree); } while (elements.Count() == 0 && sw.Elapsed < timeout); Log.Debug(string.Format("OpenRPA.SAP::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count())); if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } if (elements.Count() < 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 <SAPElement> _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); } }
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(); 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); IEnumerator <NMElement> _enum = elements.ToList().GetEnumerator(); bool more = _enum.MoveNext(); if (more) { if (elements.Count() > 1) { context.SetValue(_elements, _enum); } context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } else if (elements.Length < minresults) { throw new Interfaces.ElementNotFoundException("Failed locating " + minresults + " item"); } }
protected override void AfterExecute(NativeActivityContext context, object result) { var allelements = context.GetValue(_allelements); if (allelements == null) { allelements = new NMElement[] { } } ; var maxresults = MaxResults.Get(context); var minresults = MinResults.Get(context); NMElement[] elements = result as NMElement[]; if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } if ((elements.Length + allelements.Length) < minresults) { Log.Selector(string.Format("Windows.GetElement::Failed locating " + minresults + " item(s)")); throw new ElementNotFoundException("Failed locating " + minresults + " item(s)"); } IEnumerator <NMElement> _enum = elements.ToList().GetEnumerator(); bool more = _enum.MoveNext(); if (more) { allelements = allelements.Concat(elements).ToArray(); var eq = new Activities.NMEqualityComparer(); allelements = allelements.Distinct(eq).ToArray(); } context.SetValue(_allelements, allelements); context.SetValue(Elements, allelements); Log.Selector("END:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); if (more) { context.SetValue(_elements, _enum); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }
protected override void StartLoop(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; } 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 NM.GetElements is above 5 minutes, was this the intention ? calculated value " + timeout.ToString()); } } NMElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); string browser = sel.browser; if (WaitForReady.Get(context)) { if (from != null) { browser = from.browser; } DoWaitForReady(browser); } var allelements = context.GetValue(_allelements); if (allelements == null) { allelements = new NMElement[] { } } ; var s = new NMSelectorItem(sel[0]); if (!string.IsNullOrEmpty(s.url)) { var tab = NMHook.FindTabByURL(browser, s.url); if (tab != null) { if (!tab.highlighted || !tab.selected) { var _tab = NMHook.selecttab(browser, tab.id); } } } do { elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults); Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); // allelements = allelements.Concat(elements).ToArray(); if (allelements.Length > 0) { var newelements = new List <NMElement>(); for (var i = elements.Length - 1; i >= 0; i--) { var element = elements[i]; if (!allelements.Contains(element)) { newelements.Insert(0, element); } } elements = newelements.ToArray(); //if(elements.Count() > 20) //{ // for(var i=0; i < allelements.Length && i < elements.Length; i++) // { // if (!eq.Equals(allelements[i], elements[i]) || allelements[i].GetHashCode() != elements[i].GetHashCode()) // { // Log.Output(allelements[i].GetHashCode() + " / " + elements[i].GetHashCode()); // } // } //} } } while (elements.Count() == 0 && sw.Elapsed < timeout); if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } if ((elements.Length + allelements.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) { allelements = allelements.Concat(elements).ToArray(); var eq = new Activities.NMEqualityComparer(); allelements = allelements.Distinct(eq).ToArray(); //var allelementslength = allelements.Length; //Array.Resize(ref allelements, allelements.Length + elements.Length); //Array.Copy(elements, 0, allelements, allelementslength, elements.Length); } context.SetValue(_allelements, allelements); context.SetValue(Elements, allelements); Log.Selector("END:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); if (more) { context.SetValue(_elements, _enum); IncIndex(context); SetTotal(context, allelements.Length); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }
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); } }
protected override void Execute(NativeActivityContext context) { var folder = Folder.Get(context); var maxresults = MaxResults.Get(context); var filter = Filter.Get(context); if (string.IsNullOrEmpty(folder)) { return; } var outlookApplication = CreateOutlookInstance(); if (outlookApplication.ActiveExplorer() == null) { Log.Warning("Outlook not running!"); return; } MAPIFolder inBox = (MAPIFolder)outlookApplication.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox); // MAPIFolder folderbase = inBox.Store.GetRootFolder(); var folderbase = outlookApplication.GetNamespace("MAPI"); MAPIFolder mfolder = GetFolder(folderbase, folder); Items Items = mfolder.Items; var unreadonly = UnreadOnly.Get(context); if (unreadonly) { if (string.IsNullOrEmpty(filter)) { filter = ""; } //if (!filter.ToLower().Contains("[unread]") && filter.ToLower().Contains("httpmail:read")) //{ if (string.IsNullOrEmpty(filter)) { filter = "[Unread]=true"; } else { filter += "and [Unread]=true"; } // } // var Filter = "@SQL=" + (char)34 + "urn:schemas:httpmail:hasattachment" + (char)34 + "=1 AND " + // var Filter = "@SQL=" + (char)34 + "urn:schemas:httpmail:read" + (char)34 + "=0"; } else { } if (!string.IsNullOrEmpty(filter)) { Items = Items.Restrict(filter); } var result = new List <email>(); foreach (var folderItem in Items) { MailItem mailItem = folderItem as MailItem; if (mailItem != null) { var _e = new email(mailItem); result.Add(_e); if (result.Count == maxresults) { break; } } } Emails.Set(context, result); IEnumerator <email> _enum = result.ToList().GetEnumerator(); context.SetValue(_elements, _enum); bool more = _enum.MoveNext(); if (more) { context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }
protected override void StartLoop(NativeActivityContext context) { var SelectorString = Selector.Get(context); SelectorString = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(SelectorString, context.DataContext); var sel = new SAPSelector(SelectorString); var timeout = Timeout.Get(context); var maxresults = MaxResults.Get(context); var minresults = MinResults.Get(context); var flatternguitree = FlatternGuiTree.Get(context); //var from = From.Get(context); SAPElement from = null; if (maxresults < 1) { maxresults = 1; } 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 SAP.GetElements is above 5 minutes, was this the intention ? calculated value " + timeout.ToString()); } } SAPElement[] elements = { }; var sw = new Stopwatch(); sw.Start(); do { var selector = new SAPSelector(SelectorString); elements = SAPSelector.GetElementsWithuiSelector(selector, from, 0, maxresults, flatternguitree); } while (elements.Count() == 0 && sw.Elapsed < timeout); Log.Debug(string.Format("OpenRPA.SAP::GetElement::found {1} elements in {0:mm\\:ss\\.fff}", sw.Elapsed, elements.Count())); if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } if (elements.Count() < 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 <SAPElement> _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); } }
protected override void StartLoop(NativeActivityContext context) { WindowsCacheExtension ext = context.GetExtension <WindowsCacheExtension>(); var sw = new Stopwatch(); sw.Start(); Log.Selector(string.Format("Windows.GetElement::begin {0:mm\\:ss\\.fff}", sw.Elapsed)); UIElement[] elements = null; var selector = Selector.Get(context); selector = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selector, context.DataContext); var sel = new WindowsSelector(selector); var timeout = Timeout.Get(context); var maxresults = MaxResults.Get(context); var minresults = MinResults.Get(context); if (maxresults < 1) { maxresults = 1; } var interactive = Interactive.Get(context); var from = From.Get(context); int failcounter = 0; do { if (ClearCache != null && ClearCache.Get(context)) { Log.Selector(string.Format("Windows.GetElement::Clearing windows element cache {0:mm\\:ss\\.fff}", sw.Elapsed)); WindowsSelectorItem.ClearCache(); } if (PluginConfig.get_elements_in_different_thread) { elements = OpenRPA.AutomationHelper.RunSTAThread <UIElement[]>(() => { try { Log.Selector(string.Format("Windows.GetElement::GetElementsWithuiSelector in non UI thread {0:mm\\:ss\\.fff}", sw.Elapsed)); return(WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults, ext)); } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { Log.Error(ex.ToString()); } return(new UIElement[] { }); }, PluginConfig.search_timeout).Result; } else { Log.Selector(string.Format("Windows.GetElement::GetElementsWithuiSelector using UI thread {0:mm\\:ss\\.fff}", sw.Elapsed)); elements = WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults, ext); if (elements == null || elements.Length == 0) { elements = WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults, ext); } } //elements = WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults); if (elements == null) { elements = new UIElement[] { }; } if (elements.Length == 0) { Log.Selector(string.Format("Windows.GetElement::Found no elements {0:mm\\:ss\\.fff}", sw.Elapsed)); failcounter++; } if (failcounter > 2) { WindowsSelectorItem.ClearCache(); } } while (elements != null && elements.Length == 0 && sw.Elapsed < timeout); if (PluginConfig.get_elements_in_different_thread && elements.Length > 0) { // Get them again, we need the COM objects to be loaded in the UI thread elements = WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults, ext); } context.SetValue(Elements, elements); var lastelements = context.GetValue(_lastelements); if (lastelements == null) { lastelements = new UIElement[] { } } ; 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 <UIElement> _enum = elements.ToList().GetEnumerator(); bool more = _enum.MoveNext(); if (lastelements.Length == elements.Length && lastelements.Length > 0) { more = !System.Collections.StructuralComparisons.StructuralEqualityComparer.Equals(lastelements, elements); } if (more) { if (interactive) { var testelement = _enum.Current; Wait.UntilResponsive(testelement.RawElement, PluginConfig.search_timeout); } context.SetValue(_elements, _enum); context.SetValue(_sw, sw); Log.Selector(string.Format("Windows.GetElement::end:: call ScheduleAction: {0:mm\\:ss\\.fff}", sw.Elapsed)); IncIndex(context); SetTotal(context, elements.Length); context.ScheduleAction <UIElement>(Body, _enum.Current, OnBodyComplete); } else { Log.Selector(string.Format("Windows.GetElement:end {0:mm\\:ss\\.fff}", sw.Elapsed)); } }
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); } }
protected override async Task <object> ExecuteAsync(NativeActivityContext context) { IsCancel = false; 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 = { }; string browser = sel.browser; if (WaitForReady != null && WaitForReady.Get(context)) { if (from != null) { browser = from.browser; } DoWaitForReady(browser); } var allelements = context.GetValue(_allelements); if (allelements == null) { allelements = new NMElement[] { } } ; var s = new NMSelectorItem(sel[0]); if (!string.IsNullOrEmpty(s.url)) { var tab = NMHook.FindTabByURL(browser, s.url); if (tab != null) { if (!tab.highlighted || !tab.selected) { var _tab = NMHook.selecttab(browser, tab.id); } } } await Task.Run(() => { Stopwatch sw = new Stopwatch(); sw.Start(); do { elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults); Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); if (allelements.Length > 0) { var newelements = new List <NMElement>(); for (var i = elements.Length - 1; i >= 0; i--) { var element = elements[i]; if (!allelements.Contains(element)) { newelements.Insert(0, element); } } elements = newelements.ToArray(); } } while (elements.Count() == 0 && sw.Elapsed < timeout && !IsCancel); if (IsCancel) { Console.WriteLine("was Canceled: true! DisplayName" + DisplayName); } //if (sw.Elapsed >= timeout) //{ // Console.WriteLine("Timeout !"); //} }); return(elements); }
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); } }
protected override void Execute(NativeActivityContext context) { var sw = new Stopwatch(); sw.Start(); Log.Selector(string.Format("Windows.GetElement::begin {0:mm\\:ss\\.fff}", sw.Elapsed)); UIElement[] elements = null; var selector = Selector.Get(context); var sel = new WindowsSelector(selector); var timeout = Timeout.Get(context); var maxresults = MaxResults.Get(context); var minresults = MinResults.Get(context); if (maxresults < 1) { maxresults = 1; } var from = From.Get(context); // double _timeout = 250; double _timeout = 5000; if (PluginConfig.search_descendants) { _timeout = 5000; } //#if DEBUG // _timeout = _timeout * 8; //#endif do { if (PluginConfig.get_elements_in_different_thread) { elements = OpenRPA.AutomationHelper.RunSTAThread <UIElement[]>(() => { try { Log.Selector(string.Format("Windows.GetElement::GetElementsWithuiSelector in non UI thread {0:mm\\:ss\\.fff}", sw.Elapsed)); return(WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults)); } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { Log.Error(ex, ""); } return(new UIElement[] { }); }, TimeSpan.FromMilliseconds(_timeout)).Result; } else { Log.Selector(string.Format("Windows.GetElement::GetElementsWithuiSelector using UI thread {0:mm\\:ss\\.fff}", sw.Elapsed)); elements = WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults); } //elements = WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults); if (elements == null) { elements = new UIElement[] { }; } if (elements.Length == 0) { Log.Selector(string.Format("Windows.GetElement::Found no elements {0:mm\\:ss\\.fff}", sw.Elapsed)); } } while (elements != null && elements.Length == 0 && sw.Elapsed < timeout); //if (PluginConfig.get_elements_in_different_thread && elements.Length > 0) //{ // // Get them again, we need the COM objects to be loaded in the UI thread // elements = WindowsSelector.GetElementsWithuiSelector(sel, from, maxresults); //} context.SetValue(Elements, elements); if (elements.Count() < 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 <UIElement> _enum = elements.ToList().GetEnumerator(); bool more = _enum.MoveNext(); if (more) { context.SetValue(_elements, _enum); context.SetValue(_sw, sw); Log.Selector(string.Format("Windows.GetElement::end:: call ScheduleAction: {0:mm\\:ss\\.fff}", sw.Elapsed)); context.ScheduleAction <UIElement>(Body, _enum.Current, OnBodyComplete); } else { Log.Selector(string.Format("Windows.GetElement:end {0:mm\\:ss\\.fff}", sw.Elapsed)); } }
protected override async Task <object> ExecuteAsync(NativeActivityContext context) { IsCancel = false; 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 = { }; sw.Start(); string browser = sel.browser; if (WaitForReady != null && WaitForReady.Get(context)) { if (from != null) { browser = from.browser; } DoWaitForReady(browser); } var allelements = context.GetValue(_allelements); if (allelements == null) { allelements = new NMElement[] { } } ; var s = new NMSelectorItem(sel[0]); if (!string.IsNullOrEmpty(s.url)) { var tab = NMHook.tabs.Where(x => x.browser == browser && x.url.ToLower().StartsWith(s.url.ToLower())).FirstOrDefault(); if (tab != null) { if (!tab.highlighted || !tab.selected) { var _tab = NMHook.selecttab(browser, tab.id); } } } //var id = Guid.NewGuid().ToString(); //context.CreateBookmark(id, (activityContext, bookmark, value) => //{ //}); //Task.Factory.StartNew(() => //{ // // context.RemoveBookmark(id); //}); // await Task.Delay(100); await Task.Run(() => { do { elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults); Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); // allelements = allelements.Concat(elements).ToArray(); if (allelements.Length > 0) { var newelements = new List <NMElement>(); for (var i = elements.Length - 1; i >= 0; i--) { var element = elements[i]; if (!allelements.Contains(element)) { newelements.Insert(0, element); } } elements = newelements.ToArray(); //if(elements.Count() > 20) //{ // for(var i=0; i < allelements.Length && i < elements.Length; i++) // { // if (!eq.Equals(allelements[i], elements[i]) || allelements[i].GetHashCode() != elements[i].GetHashCode()) // { // Log.Output(allelements[i].GetHashCode() + " / " + elements[i].GetHashCode()); // } // } //} } } while (elements.Count() == 0 && sw.Elapsed < timeout && !IsCancel); if (IsCancel) { Console.WriteLine("was Canceled: true! DisplayName" + DisplayName); } }); return(elements); }
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(); string browser = sel.browser; if (WaitForReady.Get(context)) { if (from != null) { browser = from.browser; } DoWaitForReady(browser); } var allelements = context.GetValue(_allelements); if (allelements == null) { allelements = new NMElement[] { } } ; var s = new NMSelectorItem(sel[0]); if (!string.IsNullOrEmpty(s.url)) { var tab = NMHook.FindTabByURL(browser, s.url); if (tab != null) { if (!tab.highlighted || !tab.selected) { var _tab = NMHook.selecttab(browser, tab.id); } } } do { elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults); Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); // allelements = allelements.Concat(elements).ToArray(); if (allelements.Length > 0) { var newelements = new List <NMElement>(); for (var i = elements.Length - 1; i >= 0; i--) { var element = elements[i]; if (!allelements.Contains(element)) { newelements.Insert(0, element); } } elements = newelements.ToArray(); //if(elements.Count() > 20) //{ // for(var i=0; i < allelements.Length && i < elements.Length; i++) // { // if (!eq.Equals(allelements[i], elements[i]) || allelements[i].GetHashCode() != elements[i].GetHashCode()) // { // Log.Output(allelements[i].GetHashCode() + " / " + elements[i].GetHashCode()); // } // } //} } } while (elements.Count() == 0 && sw.Elapsed < timeout); if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } if ((elements.Length + allelements.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) { allelements = allelements.Concat(elements).ToArray(); var eq = new Activities.NMEqualityComparer(); allelements = allelements.Distinct(eq).ToArray(); //var allelementslength = allelements.Length; //Array.Resize(ref allelements, allelements.Length + elements.Length); //Array.Copy(elements, 0, allelements, allelementslength, elements.Length); } context.SetValue(_allelements, allelements); context.SetValue(Elements, allelements); Log.Selector("END:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); if (more) { context.SetValue(_elements, _enum); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }
protected override void Execute(NativeActivityContext context) { var eq = new Activities.NMEqualityComparer(); 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(); string browser = sel.browser; if (WaitForReady.Get(context)) { if (from != null) { browser = from.browser; } DoWaitForReady(browser); } var s = new NMSelectorItem(sel[0]); if (!string.IsNullOrEmpty(s.url)) { var tab = NMHook.tabs.Where(x => x.browser == browser && x.url.ToLower().StartsWith(s.url.ToLower())).FirstOrDefault(); if (tab != null) { if (!tab.highlighted || !tab.selected) { var _tab = NMHook.selecttab(browser, tab.id); } } } do { elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults); } while (elements.Count() == 0 && sw.Elapsed < timeout); if (elements.Count() > maxresults) { elements = elements.Take(maxresults).ToArray(); } var lastelements = context.GetValue(_lastelements); if (lastelements == null) { lastelements = new NMElement[] { } } ; context.SetValue(_lastelements, elements); if (lastelements.Length > 0) { var newelements = new List <NMElement>(); for (var i = elements.Length - 1; i >= 0; i--) { var element = elements[i]; bool exists = false; foreach (var ele in lastelements) { if (eq.Equals(ele, element)) { exists = true; break; } else if (element.ToString() == ele.ToString()) { var b = eq.Equals(ele, element); } } if (!exists) { newelements.Insert(0, element); } } if (elements.Length > 0) { elements = newelements.ToArray(); newelements = new List <NMElement>(); for (var i = elements.Length - 1; i >= 0; i--) { bool exists = false; foreach (var ele in lastelements) { if (eq.Equals(ele, elements[i])) { exists = true; break; } } if (!exists) { newelements.Insert(0, elements[i]); } } elements = newelements.ToArray(); } } 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); } var allelements = context.GetValue(_allelements); if (more) { if (allelements == null) { allelements = new NMElement[] { } } ; var allelementslength = allelements.Length; Array.Resize(ref allelements, allelements.Length + elements.Length); Array.Copy(elements, 0, allelements, allelementslength, elements.Length); } context.SetValue(Elements, allelements); context.SetValue(_allelements, allelements); }
protected override void StartLoop(NativeActivityContext context) { var folder = Folder.Get(context); var maxresults = MaxResults.Get(context); var filter = Filter.Get(context); if (string.IsNullOrEmpty(folder)) { return; } var outlookApplication = CreateOutlookInstance(); if (outlookApplication.ActiveExplorer() == null) { Log.Warning("Outlook not running!"); return; } MAPIFolder mfolder = GetFolder(outlookApplication, folder); Items Items = mfolder.Items; var unreadonly = UnreadOnly.Get(context); if (unreadonly) { if (string.IsNullOrEmpty(filter)) { filter = ""; } if (string.IsNullOrEmpty(filter)) { filter = "[Unread]=true"; } else { filter += "and [Unread]=true"; } } if (!string.IsNullOrEmpty(filter)) { Items = Items.Restrict(filter); } var result = new List <email>(); foreach (var folderItem in Items) { MailItem mailItem = folderItem as MailItem; if (mailItem != null) { var _e = new email(mailItem); result.Add(_e); if (result.Count == maxresults) { break; } } } Emails.Set(context, result); IEnumerator <email> _enum = result.ToList().GetEnumerator(); context.SetValue(_elements, _enum); bool more = _enum.MoveNext(); if (more) { IncIndex(context); SetTotal(context, result.Count); context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } }
protected override void StartLoop(NativeActivityContext context) { var filename = Filename.Get(context); var maxresults = MaxResults.Get(context); filename = Environment.ExpandEnvironmentVariables(filename); Application activeObject = null; object missing = Type.Missing; Document document = null; try { activeObject = (Application)Marshal.GetActiveObject("Word.Application"); foreach (Document current in activeObject.Documents) { if (current.FullName == filename) { document = current; break; } } } catch { activeObject = null; } finally { if (activeObject == null) { activeObject = (Application)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("000209FF-0000-0000-C000-000000000046"))); } activeObject.Visible = true; } object ofilename = filename; if (document == null) { document = activeObject.Documents.Open(ref ofilename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); } var p = document.Content.Paragraphs; string text = ""; int index = Index.Get(context); Count.Set(context, p.Count); var result = new List <string>(); if (Index.Expression == null) { for (var i = 0; i < p.Count; i++) { result.Add(p[i + 1].Range.Text); text += p[i + 1].Range.Text; if (maxresults > 0 && maxresults == result.Count) { break; } } } else { if (p.Count < index) { throw new Exception("filename only contains " + p.Count + " Paragraphs"); } for (var i = (index - 1); i < p.Count; i++) { result.Add(p[i + 1].Range.Text); text += p[i + 1].Range.Text; if (maxresults > 0 && maxresults == result.Count) { break; } } //text = p[index].Range.Text; } Text.Set(context, text); IEnumerator <string> _enum = result.ToList().GetEnumerator(); _elements.Set(context, _enum); bool more = _enum.MoveNext(); if (more) { if (Body != null) { context.ScheduleAction(Body, _enum.Current, OnBodyComplete); } } }
protected override async Task <object> ExecuteAsync(NativeActivityContext context) { IsCancel = false; 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 = { }; string browser = sel.browser; if (WaitForReady != null && WaitForReady.Get(context)) { if (from != null) { browser = from.browser; } DoWaitForReady(browser); } var allelements = context.GetValue(_allelements); if (allelements == null) { allelements = new NMElement[] { } } ; 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 NM.GetElementAsync is above 5 minutes, was this the intention ? calculated value " + timeout.ToString()); } } var s = new NMSelectorItem(sel[0]); if (!string.IsNullOrEmpty(s.url)) { var tab = NMHook.FindTabByURL(browser, s.url); if (tab != null) { if (!tab.highlighted || !tab.selected) { var _tab = NMHook.selecttab(browser, tab.id); } } } await Task.Run(() => { Stopwatch sw = new Stopwatch(); sw.Start(); do { elements = NMSelector.GetElementsWithuiSelector(sel, from, maxresults); Log.Selector("BEGIN:: I have " + elements.Count() + " elements, and " + allelements.Count() + " in all elements"); if (allelements.Length > 0) { var newelements = new List <NMElement>(); for (var i = elements.Length - 1; i >= 0; i--) { var element = elements[i]; if (!allelements.Contains(element)) { newelements.Insert(0, element); } } elements = newelements.ToArray(); } } while (elements.Count() == 0 && sw.Elapsed < timeout && !IsCancel); if (IsCancel) { Console.WriteLine("was Canceled: true! DisplayName" + DisplayName); } //if (sw.Elapsed >= timeout) //{ // Console.WriteLine("Timeout !"); //} }); return(elements); }