AutomationId keeps changing

Oct 17, 2012 at 8:31 PM

Hello, I'm trying to target nameless text boxes but their automationIds change randomly.

Here's an example of me clicking the same text box twice

1st click

Identification
    ClassName:    "TcxCustomInnerTextEdit"
    ControlType:    "ControlType.Edit"
    Culture:    "(null)"
    AutomationId:    "27004976"
    LocalizedControlType:    "edit"
    Name:    ""
    ProcessId:    "5420"
    RuntimeId:    "42 27004976"
    IsPassword:    "False"
    IsControlElement:    "True"
    IsContentElement:    "True"

 

2nd click

 Identification
    ClassName:    "TcxCustomInnerTextEdit"
    ControlType:    "ControlType.Edit"
    Culture:    "(null)"
    AutomationId:    "27660336"
    LocalizedControlType:    "edit"
    Name:    ""
    ProcessId:    "5420"
    RuntimeId:    "42 27660336"
    IsPassword:    "False"
    IsControlElement:    "True"
    IsContentElement:    "True"

 

Also, the program I am trying to automate is not my own, so I can't assign an automationId to each UI item.

Is there a way around this? Thanks.

Oct 18, 2012 at 6:33 AM

Hi

it is bad programming but if you can't change it you should use hierarchy to locate the correct way.

 

Some examples. Don't search an element in deeper structure from main window. So if the parent of your textbox don't contains other textboxes. search the parent first. And than search the textbox from the parent element.

 

MainWindow

  - Control 1

     - Control 2

          - TextBox

 

Window window = Application.GetWindow("windowname");

UIItem control1 = window.Get....

UIItem control2  = control1.Get....

TextBox box = control2.Get<TextBox>(SearchCritieria.ByControlType(ControlType.Edit));

 

if there are more TextBoxes try search by index. Or try using GetMultiple (only WPF, set using White.Core.UIItems.WPFUIItems; )

Here you get a List of Elements and you can use ,First(), .Last() or [index] to get the element.

In some cases you can also use the ClassName or other criteria.

 

Throndorin