none
How to handle continuously changing control ID's in the coded ui test?

    Question

  • I'm working on a web application. Scenario is like this, when I visit onto the webpage and find the properties of all the control then all the properties are almost same except the "ID" property. But issue in using ID as search property is this, it gets changed to any random value next time I visit the same web page again.

    How to handle such scenarios when properties value keep on changing?


    Thanks! Amandeep Singh

    Friday, July 12, 2013 10:16 AM

Answers

  • Here is a simple example:

    void VisitAllUIControls(UITestControl parent)
    {
        UITestControlCollection children = parent.GetChildren();
    
        foreach ( UITestControl child in children ) {
            ... process the child controls here ...;
        }
    }

    Regards

    Adrian

    • Marked as answer by aman.mca.pu Wednesday, July 17, 2013 12:22 PM
    Wednesday, July 17, 2013 10:32 AM

All replies

  • Hello,

    Thank you for your post.

    In this case, if the random ID values have the same part, you can search the constant part of ID property  like this: window.SearchProperties.Add("ID","TheConstantPartOfID",PropertyExpressionOperator.Contains)

    For more information, please see: http://blogs.msdn.com/b/anutthara/archive/2009/08/19/using-regular-expressions-to-locate-controls-in-coded-ui-test.aspx

    If the random ID values don’t have similar part, I don’t find other methods to resolve this issue. I am afraid that you have to contact the development team to suggest them to make the ID property static or make greater unique properties for the control.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 15, 2013 7:11 AM
    Moderator
  • Hey, thanks for replying!

    The controls of UI do have some static part in their ID's, like

    ext-gen1234, ext-gen2345,ext-gen3456 and so on...

    But the reason why I could not use the suggested approach of "PropertyExpressionOperator.Contains" is that this portion of ID is same for all types of controls. Means it is same for EditBox and Button and Image etc...


    Thanks! Amandeep Singh

    Tuesday, July 16, 2013 7:49 AM
  • Hello,

    Glad to receive your reply.

    In this case, you have to contact the development team to suggest them to make the ID property static or make greater unique properties for the controls.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 16, 2013 8:05 AM
    Moderator
  • Well, as of now it is not very feasible to get unique properties of controls. But I got another lead in it. If that can be of any help.

    I talked with a dev guy and he told me that in the parent control of any controls to be identified, they put a hidden custom control. That hidden custom control does have unique identification property. With coded UI, I am able to find that hidden control. Can I use this control to reach to the sibling control of it. Both of these controls have same parent. I was exploring"SearchConfiguration.NextSiblingfor it, but since I am working on web application, this thing is not applicable here. 

    Do we have any similar facility in web?


    Thanks! Amandeep Singh

    Tuesday, July 16, 2013 12:22 PM
  • I have not used NextSibling, but I have used GetChildren. It returns a collection whose member can easily be examined.

    Regards

    Adrian

    Tuesday, July 16, 2013 12:39 PM
  • How can we traverse through the children in this case?

    Thanks! Amandeep Singh

    Wednesday, July 17, 2013 10:19 AM
  • Here is a simple example:

    void VisitAllUIControls(UITestControl parent)
    {
        UITestControlCollection children = parent.GetChildren();
    
        foreach ( UITestControl child in children ) {
            ... process the child controls here ...;
        }
    }

    Regards

    Adrian

    • Marked as answer by aman.mca.pu Wednesday, July 17, 2013 12:22 PM
    Wednesday, July 17, 2013 10:32 AM
  • Thanks guyz for all your help. Marking this as answer!

    Thanks! Amandeep Singh

    • Marked as answer by aman.mca.pu Wednesday, July 17, 2013 12:22 PM
    • Unmarked as answer by aman.mca.pu Wednesday, July 17, 2013 12:22 PM
    Wednesday, July 17, 2013 12:22 PM