public override ITextRange RangeFromChild(SHAutomationElement child) { var nativeChild = SHAutomationElementConverter.ToNative(child); var nativeRange = Com.Call(() => NativePattern.RangeFromChild(nativeChild)); return(TextRangeConverter.NativeToManaged((UIA3Automation)FrameworkAutomationElement.Automation, nativeRange)); }
public void HandleStructureChangedEvent(UIA.IUIAutomationElement sender, UIA.StructureChangeType changeType, int[] runtimeId) { var frameworkElement = new UIA3FrameworkAutomationElement((UIA3Automation)Automation, sender); var senderElement = new SHAutomationElement(frameworkElement); HandleStructureChangedEvent(senderElement, (StructureChangeType)changeType, runtimeId); }
/// <summary> /// Gets the XPath to the element until the desktop or the given root element. /// Warning: This is quite a heavy operation /// </summary> public static string GetXPathToElement(SHAutomationElement element, SHAutomationElement rootElement = null) { _callingRoot = rootElement; var treeWalker = element.Automation.TreeWalkerFactory.GetControlViewWalker(); return(GetXPathToElement(element, treeWalker, rootElement)); }
public void HandleFocusChangedEvent(UIA.IUIAutomationElement sender) { var frameworkElement = new UIA3FrameworkAutomationElement((UIA3Automation)Automation, sender); var senderElement = new SHAutomationElement(frameworkElement); HandleFocusChangedEvent(senderElement); }
public ITextRange RangeFromAnnotation(SHAutomationElement annotation) { var nativeInputElement = SHAutomationElementConverter.ToNative(annotation); var nativeElement = Com.Call(() => ExtendedNativePattern.RangeFromAnnotation(nativeInputElement)); return(TextRangeConverter.NativeToManaged((UIA3Automation)FrameworkAutomationElement.Automation, nativeElement)); }
/// <inheritdoc /> public SHAutomationElement GetPreviousSibling(SHAutomationElement element) { var child = NativeTreeWalker.GetPreviousSiblingElement(SHAutomationElementConverter.ToNative(element)); return(Automation.WrapNativeElement(child)); }
/// <inheritdoc /> public SHAutomationElement GetLastChild(SHAutomationElement element) { var child = NativeTreeWalker.GetLastChildElement(SHAutomationElementConverter.ToNative(element)); return(Automation.WrapNativeElement(child)); }
/// <inheritdoc /> public SHAutomationElement GetParent(SHAutomationElement element) { var parent = NativeTreeWalker.GetParentElement(SHAutomationElementConverter.ToNative(element)); return(Automation.WrapNativeElement(parent)); }
private static string GetXPathToElement(SHAutomationElement element, ITreeWalker treeWalker, SHAutomationElement rootElement = null) { var parent = treeWalker.GetParent(element); if (parent == null || (rootElement != null && parent.Equals(_callingRoot.Parent))) { _callingRoot = null; return(string.Empty); } // Get the index var allChildren = parent.FindAllChildren(cf => cf.ByControlType(element.Properties.ControlType)); var currentItemText = $"{element.Properties.ControlType.Value}"; if (allChildren.Length > 1) { // There is more than one matching child, find out the index var indexInParent = 1; // Index starts with 1 foreach (var child in allChildren) { if (child.Equals(element)) { break; } indexInParent++; } currentItemText += $"[{indexInParent}]"; } return($"{GetXPathToElement(parent, treeWalker, rootElement)}/{currentItemText}"); }
public void HandleTextEditTextChangedEvent(UIA.IUIAutomationElement sender, UIA.TextEditChangeType textEditChangeType, string[] eventstrings) { var frameworkElement = new UIA3FrameworkAutomationElement((UIA3Automation)Automation, sender); var senderElement = new SHAutomationElement(frameworkElement); HandleTextEditTextChangedEvent(senderElement, (TextEditChangeType)textEditChangeType, eventstrings); }
public void HandleNotificationEvent(UIA.IUIAutomationElement sender, UIA.NotificationKind notificationKind, UIA.NotificationProcessing notificationProcessing, string displaystring, string activityId) { var frameworkElement = new UIA3FrameworkAutomationElement((UIA3Automation)Automation, sender); var senderElement = new SHAutomationElement(frameworkElement); HandleNotificationEvent(senderElement, (NotificationKind)notificationKind, (NotificationProcessing)notificationProcessing, displaystring, activityId); }
public void HandleActiveTextPositionChangedEvent(UIA.IUIAutomationElement sender, UIA.IUIAutomationTextRange range) { var frameworkElement = new UIA3FrameworkAutomationElement((UIA3Automation)Automation, sender); var senderElement = new SHAutomationElement(frameworkElement); var rangeElement = new UIA3TextRange((UIA3Automation)Automation, range); HandleActiveTextPositionChangedEvent(senderElement, rangeElement); }
public void HandlePropertyChangedEvent(UIA.IUIAutomationElement sender, int propertyId, object newValue) { var frameworkElement = new UIA3FrameworkAutomationElement((UIA3Automation)Automation, sender); var senderElement = new SHAutomationElement(frameworkElement); var property = PropertyId.Find(Automation.AutomationType, propertyId); HandlePropertyChangedEvent(senderElement, property, newValue); }
public void HandleAutomationEvent(UIA.IUIAutomationElement sender, int eventId) { var frameworkElement = new UIA3FrameworkAutomationElement((UIA3Automation)Automation, sender); var senderElement = new SHAutomationElement(frameworkElement); var @event = EventId.Find(AutomationType.UIA3, eventId); HandleAutomationEvent(senderElement, @event); }
public SHAutomationElement FindItemByProperty(SHAutomationElement startAfter, PropertyId property, object value) { var foundNativeElement = Com.Call(() => NativePattern.FindItemByProperty( SHAutomationElementConverter.ToNative(startAfter), property?.Id ?? 0, ValueConverter.ToNative(value))); return(SHAutomationElementConverter.NativeToManaged((UIA3Automation)FrameworkAutomationElement.Automation, foundNativeElement)); }
public static bool UntilResponsive(SHAutomationElement sHAutomationElement, TimeSpan timeout) { var currentElement = sHAutomationElement; var treeWalker = sHAutomationElement.Automation.TreeWalkerFactory.GetControlViewWalker(); while (currentElement.Properties.NativeWindowHandle.ValueOrDefault == new IntPtr(0)) { currentElement = treeWalker.GetParent(currentElement); } return(UntilResponsive(currentElement.Properties.NativeWindowHandle, timeout)); }
/// <summary> /// Captures a rectangle inside an element and returns the image. /// </summary> public static CaptureImage ElementRectangle(SHAutomationElement element, Rectangle rectangle, CaptureSettings settings = null) { var elementBounds = element.BoundingRectangle; // Calculate the rectangle that should be captured var capturingRectangle = new Rectangle(elementBounds.Left + rectangle.Left, elementBounds.Top + rectangle.Top, rectangle.Width, rectangle.Height); // Check if the element contains the rectangle that should be captured if (!elementBounds.Contains(capturingRectangle)) { throw new SHAutomationException($"The given rectangle ({capturingRectangle}) is out of bounds of the element ({elementBounds})."); } return(Rectangle(capturingRectangle, settings)); }
public static void RealizeItems(SHAutomationElement itemContainerElement) { // We save the scroll value to restore it afterwards var scrollPattern = itemContainerElement.Patterns.Scroll.PatternOrDefault; double currHScroll = 0; double currVScroll = 0; if (scrollPattern != null) { currHScroll = scrollPattern.HorizontalScrollPercent; currVScroll = scrollPattern.VerticalScrollPercent; } // First we try with the item container pattern and realize each item var itemContainerPattern = itemContainerElement.Patterns.ItemContainer.PatternOrDefault; if (itemContainerPattern != null) { // There's the item container pattern so we can go thru all elements and just realize them SHAutomationElement currElement = null; while (true) { currElement = itemContainerPattern.FindItemByProperty(currElement, null, null); if (currElement == null) { break; } var vp = currElement.Patterns.VirtualizedItem.PatternOrDefault; vp?.Realize(); } ResetScroll(scrollPattern, currHScroll, currVScroll); return; } // Second we use the scroll pattern to scroll from top to bottom if (scrollPattern != null) { scrollPattern.SetScrollPercent(0, 0); do { scrollPattern.Scroll(ScrollAmount.NoAmount, ScrollAmount.SmallIncrement); } while (scrollPattern.VerticalScrollPercent < 100); ResetScroll(scrollPattern, currHScroll, currVScroll); return; } // Third we try by using the scrollbar controls itself { // TODO } }
public static UIA.IUIAutomationElement ToNative(SHAutomationElement sHAutomationElement) { if (sHAutomationElement?.FrameworkAutomationElement == null) { return(null); } var frameworkElement = sHAutomationElement.FrameworkAutomationElement as UIA3FrameworkAutomationElement; if (frameworkElement == null) { throw new Exception("Element is not an UIA3 element"); } return(frameworkElement.NativeElement); }
/// <inheritdoc /> public override bool MoveToParent() { if (IsInAttribute) { _attributeIndex = NoAttributeValue; return(true); } if (_currentElement.Equals(_rootElement)) { return(false); } _currentElement = _treeWalker.GetParent(_currentElement); return(true); }
/// <inheritdoc /> public override bool MoveToPrevious() { if (IsInAttribute) { return(false); } var previousElement = _treeWalker.GetPreviousSibling(_currentElement); if (previousElement == null) { return(false); } _currentElement = previousElement; return(true); }
/// <inheritdoc /> public override bool MoveToNext() { if (IsInAttribute) { return(false); } var nextElement = _treeWalker.GetNextSibling(_currentElement); if (nextElement == null) { return(false); } _currentElement = nextElement; return(true); }
/// <inheritdoc /> public override bool MoveToFirstChild() { if (IsInAttribute) { return(false); } var childElement = _treeWalker.GetFirstChild(_currentElement); if (childElement == null) { return(false); } _currentElement = childElement; return(true); }
/// <inheritdoc /> public override bool MoveTo(XPathNavigator other) { var specificNavigator = other as SHAutomationElementXPathNavigator; if (specificNavigator == null) { return(false); } if (!_rootElement.Equals(specificNavigator._rootElement)) { return(false); } _currentElement = specificNavigator._currentElement; _attributeIndex = specificNavigator._attributeIndex; return(true); }
public static void HighlightElement(SHAutomationElement sHAutomationElement) { if (UseElementHighlighter) { try { if (sHAutomationElement.SupportsBoundingRectangle) { sHAutomationElement.DrawHighlight(true, HighlightColour, TimeSpan.FromMilliseconds(100)); } } catch { } } }
public static SHAutomationElement[] NativeArrayToManaged(AutomationBase automation, object nativeElements) { if (nativeElements == null) { return(Array.Empty <SHAutomationElement>()); } var uia3Automation = (UIA3Automation)automation; var nativeElementsCasted = (UIA.IUIAutomationElementArray)nativeElements; var retArray = new SHAutomationElement[nativeElementsCasted.Length]; for (var i = 0; i < nativeElementsCasted.Length; i++) { var nativeElement = nativeElementsCasted.GetElement(i); var SHAutomationElement = uia3Automation.WrapNativeElement(nativeElement); retArray[i] = SHAutomationElement; } return(retArray); }
/// <inheritdoc /> public override SHAutomationElement FindFirstWithOptions(TreeScope treeScope, ConditionBase condition, TreeTraversalOption traversalOptions, SHAutomationElement root) { var nativeFoundElement = NativeElement7.FindFirstWithOptions((UIA.TreeScope)treeScope, ConditionConverter.ToNative(Automation, condition), (UIA.TreeTraversalOptions)traversalOptions, SHAutomationElementConverter.ToNative(root)); return(SHAutomationElementConverter.NativeToManaged(Automation, nativeFoundElement)); }
protected void HandleNotificationEvent(SHAutomationElement sender, NotificationKind notificationKind, NotificationProcessing notificationProcessing, string displaystring, string activityId) { _callAction(sender, notificationKind, notificationProcessing, displaystring, activityId); }
/// <summary> /// Compares two automation elements for equality. /// </summary> public abstract bool Compare(SHAutomationElement element1, SHAutomationElement element2);
/// <summary> /// Finds the first matching element in the specified order. /// </summary> /// <param name="treeScope">A combination of values specifying the scope of the search.</param> /// <param name="condition">A condition that represents the criteria to match.</param> /// <param name="traversalOptions">Value specifying the tree navigation order.</param> /// <param name="root">An element with which to begin the search.</param> /// <returns>The found element or null if no element was found.</returns> public abstract SHAutomationElement FindFirstWithOptions(TreeScope treeScope, ConditionBase condition, TreeTraversalOption traversalOptions, SHAutomationElement root);