/// <summary>
        /// Sets the current value of the UI Automation element
        /// </summary>
        /// <param name="control">The UI Automation element.</param>
        /// <param name="value">The value to set the control to.</param>
        internal static void SetValue(AutomationElement control, double value)
        {
            RangeValuePattern pattern = (RangeValuePattern)CommonUIAPatternHelpers.CheckPatternSupport(RangeValuePattern.Pattern, control);

            pattern.SetValue(value);
            ValueVerifier <double, double> .Verify(value, GetValue(control));
        }
        /// <summary>
        /// Expands the text range to the specified TextUnit.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="unit">The textual unit.</param>
        internal static void ExpandToEnclosingUnit(AutomationElement control, TextUnit unit)
        {
            TextPattern pat = (TextPattern)CommonUIAPatternHelpers.CheckPatternSupport(TextPattern.Pattern, control);

            TextPatternRange[] selection = pat.GetSelection();
            selection[0].ExpandToEnclosingUnit(unit);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the number of rows
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        /// The number of rows
        /// </returns>
        internal static int GetRowCount(AutomationElement control)
        {
            /* move to next state */
            TablePattern pat = (TablePattern)CommonUIAPatternHelpers.CheckPatternSupport(TablePattern.Pattern, control);

            return(pat.Current.RowCount);
        }
        /// <summary>
        /// Highlights text in the text control corresponding to the text range Start and End endpoints
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="targetRange">The text range to select.</param>
        internal static void Select(AutomationElement control, TextPatternRange targetRange)
        {
            CommonUIAPatternHelpers.CheckPatternSupport(TextPattern.Pattern, control);

            targetRange.Select();
            targetRange.ScrollIntoView(true);
        }
Beispiel #5
0
        /// <summary>
        /// Gets a UI Automation provider that implements IGridProvider and represents the container of the cell or item
        /// </summary>
        /// <param name="item">The UI Automation element</param>
        /// <returns>
        /// A UI Automation provider that implements the GridPattern and represents the cell or item container
        /// </returns>
        internal static AutomationElement GetContainingGrid(AutomationElement item)
        {
            /* move to next state */
            TableItemPattern pat = (TableItemPattern)CommonUIAPatternHelpers.CheckPatternSupport(TableItemPattern.Pattern, item);

            return(pat.Current.ContainingGrid);
        }
Beispiel #6
0
        /// <summary>
        /// Gets the ordinal number of the row that contains the cell or item.
        /// </summary>
        /// <param name="item">The UI Automation element.</param>
        /// <returns>
        /// A zero-based ordinal number that identifies the row containing the cell or item
        /// </returns>
        internal static int GetRowIndex(AutomationElement item)
        {
            /* move to next state */
            TableItemPattern pat = (TableItemPattern)CommonUIAPatternHelpers.CheckPatternSupport(TableItemPattern.Pattern, item);

            return(pat.Current.Row);
        }
        /// <summary>
        /// Retrieves a collection of all embedded objects that fall within the text range.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="targetRange">The target range to search for the objects.</param>
        /// <returns>
        /// A collection of all child objects that fall within the range. Children that overlap with the range but are not entirely enclosed by
        /// it will also be included in the collection. Returns an empty collection if there are no child objects
        /// </returns>
        internal static List <AutomationElement> GetChildren(AutomationElement control, TextPatternRange targetRange)
        {
            CommonUIAPatternHelpers.CheckPatternSupport(TextPattern.Pattern, control);
            List <AutomationElement> childElements = new List <AutomationElement>(targetRange.GetChildren());

            return(childElements);
        }
        internal static object GetTextAttribute(AutomationElement control, AutomationTextAttribute attribute)
        {
            TextPattern pat    = (TextPattern)CommonUIAPatternHelpers.CheckPatternSupport(TextPattern.Pattern, control);
            object      retVal = pat.DocumentRange.GetAttributeValue(attribute);

            return(retVal);
        }
Beispiel #9
0
        /// <summary>
        /// Sets the TextBox value to the supplied value, overwriting any existing text
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="text">Text to set Textbox value to</param>
        internal static void SetValue(AutomationElement control, string text)
        {
            ValuePattern pattern = (ValuePattern)CommonUIAPatternHelpers.CheckPatternSupport(ValuePattern.Pattern, control);

            pattern.SetValue(text);

            ValueVerifier <string, string> .Verify(text, GetValue(control));
        }
        /// <summary>
        /// Gets the interaction state of the window
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        /// The current <see cref="WindowInteractionState"/>
        /// </returns>
        internal static WindowInteractionState GetInteractionState(AutomationElement control)
        {
            WindowPattern pattern = (WindowPattern)CommonUIAPatternHelpers.CheckPatternSupport(WindowPattern.Pattern, control);

            return(false == pattern.WaitForInputIdle(10000)
                       ? WindowInteractionState.NotResponding
                       : pattern.Current.WindowInteractionState);
        }
Beispiel #11
0
        /// <summary>
        /// Expands the specified control.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Expand(AutomationElement control)
        {
            ExpandCollapsePattern pat = (ExpandCollapsePattern)CommonUIAPatternHelpers.CheckPatternSupport(ExpandCollapsePattern.Pattern, control);

            control.SetFocus();
            pat.Expand();
            return(0);
        }
Beispiel #12
0
        /* These are for text based controls */
        /// <summary>
        /// Appends the supplied string to the existing textBox text
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="text">Text to append to TextBox value</param>
        internal static void AppendValue(AutomationElement control, string text)
        {
            ValuePattern pattern      = (ValuePattern)CommonUIAPatternHelpers.CheckPatternSupport(ValuePattern.Pattern, control);
            string       originalText = pattern.Current.Value;
            string       appText      = originalText + text;

            pattern.SetValue(appText);

            ValueVerifier <string, string> .Verify(appText, pattern.Current.Value);
        }
Beispiel #13
0
        /// <summary>
        /// Resizes the control.
        /// </summary>
        /// <param name="control">The control to resize</param>
        /// <param name="width">desired width in pixels</param>
        /// <param name="height">the desired height in pixels</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Resize(AutomationElement control, double width, double height)
        {
            TransformPattern pat = (TransformPattern)CommonUIAPatternHelpers.CheckPatternSupport(TransformPattern.Pattern, control);

            if (pat.Current.CanResize)
            {
                pat.Resize(width, height);
                return(0);
            }
            return(-1);
        }
Beispiel #14
0
        /// <summary>
        /// Moves the control to the specified location.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="x">The top left corner</param>
        /// <param name="y">The right</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Move(AutomationElement control, double x, double y)
        {
            TransformPattern pat = (TransformPattern)CommonUIAPatternHelpers.CheckPatternSupport(TransformPattern.Pattern, control);

            if (pat.Current.CanMove)
            {
                pat.Move(x, y);
                return(0);
            }
            return(-1);
        }
Beispiel #15
0
        /// <summary>
        /// Rotates the specified control.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="degrees">The degrees to rotate. use a negative number to rotate counter-clockwise</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Rotate(AutomationElement control, double degrees)
        {
            TransformPattern pat = (TransformPattern)CommonUIAPatternHelpers.CheckPatternSupport(TransformPattern.Pattern, control);

            if (pat.Current.CanRotate)
            {
                pat.Rotate(degrees);
                return(0);
            }
            return(-1);
        }
        /// <summary>
        /// gets the Document range.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns></returns>
        internal static TextPatternRange GetDocumentRange(AutomationElement control)
        {
            TextPattern pat = (TextPattern)CommonUIAPatternHelpers.CheckPatternSupport(TextPattern.Pattern, control);

            if (pat == null)
            {
                return(null);
            }

            return(pat.DocumentRange);
        }
        /// <summary>
        /// Sets the visual state of the window
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="state">The <see cref="WindowVisualState"/> of the current window</param>
        internal static void SetVisualState(AutomationElement control, WindowVisualState state)
        {
            WindowPattern pattern = (WindowPattern)CommonUIAPatternHelpers.CheckPatternSupport(WindowPattern.Pattern, control);

            if (pattern.Current.WindowInteractionState != WindowInteractionState.ReadyForUserInteraction)
            {
                return;
            }
            SetState(state, pattern);
            ValueVerifier <WindowVisualState, WindowVisualState> .Verify(state, GetVisualState(control));
        }
        /// <summary>
        /// Searches for, then highlights text in the text control corresponding to the text range Start and End endpoints.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="find">The string to find.</param>
        /// <param name="ignoreCase">if set to <c>true</c> ignores case.</param>
        internal static void Select(AutomationElement control, string find, bool ignoreCase)
        {
            CommonUIAPatternHelpers.CheckPatternSupport(TextPattern.Pattern, control);

            TextPatternRange range = FindText(control, find, false, ignoreCase);

            if (range == null)
            {
                return;
            }
            range.Select();
            range.ScrollIntoView(true);
        }
Beispiel #19
0
        /// <summary>
        /// Inserts supplied text into existing string beginning at the specified index
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="text">Text to insert into to TextBox value</param>
        /// <param name="index">Index into string where to begin insertion</param>
        internal static void InsertValue(AutomationElement control, string text, int index)
        {
            ValuePattern pattern  = (ValuePattern)CommonUIAPatternHelpers.CheckPatternSupport(ValuePattern.Pattern, control);
            string       baseText = pattern.Current.Value;

            /* If index is out of range, defer to ProdErrorManager */
            if (baseText == null)
            {
                return;
            }
            string insString = baseText.Insert(index, text);

            pattern.SetValue(insString);
            //TODO: Find an insert text verification
        }
Beispiel #20
0
        /// <summary>
        ///     Determines whether this instance can rotate
        /// </summary>
        /// <param name = "control">The UI Automation element.</param>
        /// <returns>
        ///     Whether control can be rotated, null if InvalidOperationException is raised
        /// </returns>
        internal static bool CanRotate(AutomationElement control)
        {
            TransformPattern pat = (TransformPattern)CommonUIAPatternHelpers.CheckPatternSupport(TransformPattern.Pattern, control);

            return(pat.Current.CanRotate);
        }
        /// <summary>
        /// Gets the selected items.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        /// An AutomationElement array of all selected items
        /// </returns>
        internal static AutomationElement[] SelectedItems(AutomationElement control)
        {
            SelectionPattern pattern = (SelectionPattern)CommonUIAPatternHelpers.CheckPatternSupport(SelectionPattern.Pattern, control);

            return(pattern.Current.GetSelection());
        }
Beispiel #22
0
        /// <summary>
        ///     Gets the vertical view size
        /// </summary>
        /// <param name = "control">The UI Automation element</param>
        /// <returns>
        ///     The vertical size of the viewable region as a percentage of the total content area within the control
        /// </returns>
        internal static double GetVerticalViewSize(AutomationElement control)
        {
            ScrollPattern pat = (ScrollPattern)CommonUIAPatternHelpers.CheckPatternSupport(ScrollPattern.Pattern, control);

            return(pat.Current.VerticalViewSize);
        }
Beispiel #23
0
        /// <summary>
        /// Ensures the window pattern is supported, then invokes
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        internal static void Invoke(AutomationElement control)
        {
            InvokePattern pattern = (InvokePattern)CommonUIAPatternHelpers.CheckPatternSupport(InvokePattern.Pattern, control);

            pattern.Invoke();
        }
Beispiel #24
0
        /// <summary>
        /// Retrieves a collection of UI Automation providers representing all the row headers associated with a table item or cell
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        /// A collection of UI Automation providers
        /// </returns>
        internal static AutomationElement[] GetRowHeaderItems(AutomationElement control)
        {
            TableItemPattern pat = (TableItemPattern)CommonUIAPatternHelpers.CheckPatternSupport(TableItemPattern.Pattern, control);

            return(pat.Current.GetRowHeaderItems());
        }
Beispiel #25
0
        /// <summary>
        ///     Gets the number of columns
        /// </summary>
        /// <param name = "control">The UI Automation element</param>
        /// <returns>The number of columns</returns>
        internal static int GetColumnCount(AutomationElement control)
        {
            TablePattern pat = (TablePattern)CommonUIAPatternHelpers.CheckPatternSupport(TablePattern.Pattern, control);

            return(pat.Current.ColumnCount);
        }
        /// <summary>
        /// Retrieves the UI Automation provider for the specified cell
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="row">The ordinal number of the row of interest</param>
        /// <param name="column">The ordinal number of the column of interest.</param>
        /// <returns>
        /// An object representing the item at the specified location
        /// </returns>
        internal static AutomationElement GetItem(AutomationElement control, int row, int column)
        {
            GridPattern pat = (GridPattern)CommonUIAPatternHelpers.CheckPatternSupport(GridPattern.Pattern, control);

            return(pat.GetItem(row, column));
        }
        /// <summary>
        /// Gets the total number of rows in a grid.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        /// Total number of rows in a grid
        /// </returns>
        internal static int GetRowCount(AutomationElement control)
        {
            GridPattern pat = (GridPattern)CommonUIAPatternHelpers.CheckPatternSupport(GridPattern.Pattern, control);

            return(pat.Current.RowCount);
        }
        /// <summary>
        /// Determines whether this instance can select multiple items
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        ///   <c>true</c> if this instance can select multiple items; otherwise, <c>false</c>.
        /// </returns>
        internal static bool CanSelectMultiple(AutomationElement control)
        {
            SelectionPattern pattern = (SelectionPattern)CommonUIAPatternHelpers.CheckPatternSupport(SelectionPattern.Pattern, control);

            return(pattern.Current.CanSelectMultiple);
        }
Beispiel #29
0
        /// <summary>
        /// Gets the primary direction of traversal.
        /// </summary>
        /// <param name="control">The UI Automation element.</param>
        /// <returns></returns>
        internal static RowOrColumnMajor GetRowOrColumnMajor(AutomationElement control)
        {
            TablePattern pat = (TablePattern)CommonUIAPatternHelpers.CheckPatternSupport(TablePattern.Pattern, control);

            return(pat.Current.RowOrColumnMajor);
        }
        /// <summary>
        /// Determines whether a selection is required for the specified control.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <returns>
        ///   <c>true</c> if selection is required; otherwise, <c>false</c>.
        /// </returns>
        internal static bool IsSelectionRequired(AutomationElement control)
        {
            SelectionPattern pattern = (SelectionPattern)CommonUIAPatternHelpers.CheckPatternSupport(SelectionPattern.Pattern, control);

            return(pattern.Current.IsSelectionRequired);
        }