Problem with UI Automation


  •  Hi,

    Iam using UI automation APi for automating ASP.Net controls on Web page.

     Iam trying to identify the text box using Automation ID .The following code is intermittently working.

       aeWindow = aeDesktop.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, WindowName));
                    aeText = aeWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, TextBoxName));

    Some times Iam getting the text box and sometimes it is returning null.

    Is there any specific reason for not identifying the controls? Why it is inconsistently behaving?




    Tuesday, April 15, 2014 5:34 AM

All replies

  • I can't comment on why the behavior is inconsistent, but you could always loop while aeText == null to ensure that the harness retries until the control is found.  A bit wasteful from a performance perspective, but at least the harness would ultimately complete your testing.

    I do have a question for you, though, related to a thread I started in this forum.  How did you or your development team set the Automation ID?  As far as I know, an ASP .NET TextBox is ultimately generated into an HTML 4 Input control with Type="Text" similar to this: 

    <input name="txt1" type="text" id="txt1" class="input" />

    I am curious how an Automation ID can be set on an HTML Input with Type = "Text".  This page doesn't indicate any properties map to Automation ID, so I'm a bit perplexed:

    Your post gives me hope that it is possible, however.

    Thanks for any help

    • Edited by rustoleum Thursday, April 17, 2014 5:23 PM
    Thursday, April 17, 2014 5:19 PM
  • Thanks for your input.  My problem is not getting recognized consistently . Even if you search in While loop it fails.

    Answer to your query:

    ID property is nothing but automation ID

     please  assign the property as given below



    Thursday, April 17, 2014 7:27 PM
  • Is an exception being thrown that you should be catching?  If so, what is the exception?  I have found that I periodically received the below when doing a FindFirst or FindAll.

    Exception:      Parameters:Error HRESULT E_FAIL has been returned from a call to a COM component.

    I ended up removing FindFirst, and now use a TreeWalker and test for conditions element by element to find my desired control.  This actually works out better as I implemented regular expression support, too.

    thanks for your reply on my Automation ID query.

    Unfortunately, that is not my experience.  Here is the HTML generated for a Input control:

            <td><input name="GeneralInfoView$NameTextbox" type="text" maxlength="80" id="GeneralInfoView_NameTextbox" class="detailText" style="width:80%;" /></td>

    Here is the Inspect output of that control through IE (no AutomationID, unfortunately, despite an ID being provided):

    How found:    Mouse move (209,206)
        hwnd=0x0273026E 32bit class="Internet Explorer_Server" style=0x56000000 ex=0x0
    Name:    ""
    ControlType:    UIA_EditControlTypeId (0xC354)
    LocalizedControlType:    "edit"
    BoundingRectangle:    {l:193 t:196 r:503 b:215}
    IsEnabled:    true
    IsOffscreen:    false
    IsKeyboardFocusable:    false
    HasKeyboardFocus:    false
    AccessKey:    ""
    ProcessId:    6652
    RuntimeId:    [2A.273026E.2.B]
    ProviderDescription:    "[pid:6652,hwnd:0x0 Main(parent link):Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]"
    AriaProperties:    ""
    LiveSettingProperty:    [Not supported]
    IsPassword:    false
    FlowsFrom:    [Not supported]
    OptimizeForVisualContent:    [Not supported]
    Annotation.AnnotationAuthor:    [Not supported]
    Annotation.AnnotationTypeId:    [Not supported]
    Annotation.Author:    [Not supported]
    Annotation.DateTime:    [Not supported]
    Annotation.Target:    [Not supported]
    Drag.DropEffect:    [Not supported]
    Drag.DropEffects:    [Not supported]
    Drag.GrabbedItems:    [Not supported]
    Drag.IsGrabbed:    [Not supported]
    DropTarget.DropTargetEffect:    [Not supported]
    DropTarget.DropTargetEffects:    [Not supported]
    LegacyIAccessible.ChildId:    0
    LegacyIAccessible.Description:    ""
    LegacyIAccessible.KeyboardShortcut:    ""
    LegacyIAccessible.Name:    ""
    LegacyIAccessible.Role:    editable text (0x2A)
    LegacyIAccessible.State:    normal (0x0)
    LegacyIAccessible.Value:    ""
    ObjectModel.UnderlyingObjectModel:    [Error: calling getter for this property: hr=0x80070057 - The parameter is incorrect.]
    SpreadsheetItem.AnnotationObjects:    [Not supported]
    SpreadsheetItem.AnnotationTypes:    [Not supported]
    SpreadsheetItem.Formula:    [Not supported]
    Style.ExtendedProperties:    [Not supported]
    Style.FillColor:    [Not supported]
    Style.FillPatternColor:    [Not supported]
    Style.FillPatternStyle:    [Not supported]
    Style.Shape:    [Not supported]
    Style.StyleId:    [Not supported]
    Style.StyleName:    [Not supported]
    Value.IsReadOnly:    false
    Value.Value:    ""
    Transform2.CanZoom:    [Not supported]
    Transform2.ZoomLevel:    [Not supported]
    Transform2.ZoomMinimum:    [Not supported]
    Transform2.ZoomMaximum:    [Not supported]
    IsAnnotationPatternAvailable:    [Not supported]
    IsDragPatternAvailable:    [Not supported]
    IsDockPatternAvailable:    false
    IsDropTargetPatternAvailable:    [Not supported]
    IsExpandCollapsePatternAvailable:    false
    IsGridItemPatternAvailable:    false
    IsGridPatternAvailable:    false
    IsInvokePatternAvailable:    false
    IsItemContainerPatternAvailable:    false
    IsLegacyIAccessiblePatternAvailable:    true
    IsMultipleViewPatternAvailable:    false
    IsObjectModelPatternAvailable:    [Not supported]
    IsRangeValuePatternAvailable:    false
    IsScrollItemPatternAvailable:    false
    IsScrollPatternAvailable:    false
    IsSelectionItemPatternAvailable:    false
    IsSelectionPatternAvailable:    false
    IsSpreadsheetItemPatternAvailable:    [Not supported]
    IsSpreadsheetPatternAvailable:    [Not supported]
    IsStylesPatternAvailable:    [Not supported]
    IsSynchronizedInputPatternAvailable:    false
    IsTableItemPatternAvailable:    false
    IsTablePatternAvailable:    false
    IsTextChildPatternAvailable:    [Not supported]
    IsTextPatternAvailable:    true
    IsTextPattern2Available:    [Not supported]
    IsTogglePatternAvailable:    false
    IsTransformPatternAvailable:    false
    IsTransform2PatternAvailable:    [Not supported]
    IsValuePatternAvailable:    true
    IsVirtualizedItemPatternAvailable:    false
    IsWindowPatternAvailable:    false
    FirstChild:    [null]
    LastChild:    [null]
    Next:    [null]
    Previous:    [null]
    Other Props:    Object has no additional properties
    Children:    Container has no children

    Thursday, April 17, 2014 8:31 PM
  • Thanks for your response!. Do you have a code for treewalkar? Please post it. Let me try.

    Did you try to use UIA verify tool instead of Inspect?


    Thursday, April 17, 2014 8:36 PM