public int[] GetElements(string locatorType, string locator) { Logger.Info("Searching for elements:" + locator + " using " + locatorType); IUIItem[] items = null; var attempts = 5; while ((items == null || items.Length == 0) && attempts-- > 0) { switch (locatorType) { case "class name": items = WPFUIItem.GetMultiple(activeWindow, FromControlType(locator)); break; case "name": items = WPFUIItem.GetMultiple(activeWindow, SearchCriteria.ByText(locator)); break; case "id": items = WPFUIItem.GetMultiple(activeWindow, SearchCriteria.ByAutomationId(locator)); break; default: throw new ArgumentException("invalid locator type:" + locatorType); } Thread.Sleep(200); } if (items == null) { throw new InvalidOperationException(); } var newElements = new List <int>(); foreach (var item in items) { elements.Add(new UIElement { element = item, selector = locator }); newElements.Add(elements.Count - 1); } return(newElements.ToArray()); }
public int GetElement(string locatorType, string locator) { Logger.Info("Searching for element:" + locator + " using " + locatorType); IUIItem item = null; var attempts = 5; while (item == null && attempts-- > 0) { switch (locatorType) { case "class name": item = WPFUIItem.Get(activeWindow, SearchCriteria.ByClassName(locator)); break; case "name": item = WPFUIItem.Get(activeWindow, SearchCriteria.ByText(locator)); break; case "id": item = WPFUIItem.Get(activeWindow, SearchCriteria.ByAutomationId(locator)); break; default: throw new ArgumentException("invalid locator type:" + locatorType); } Thread.Sleep(500); } if (item == null) { throw new InvalidOperationException(); } elements.Add(new UIElement { element = item, selector = locator }); return(elements.Count - 1); }