Unable to locate element using ID.

3 posts, 0 answers
  1. Vishal
    Vishal avatar
    18 posts
    Member since:
    Jan 2014

    Posted 02 Apr 2014 Link to this post


    I have a scenario where there is Add New user and Edit User PopUp.  Both contains the same elements. I am able to identify the elements which are present in Add New PopUp but the same element I am not able to identify in Edit User PopUp. ID remains same for both.

    After consulting with the developer I came to know both are having the same view so ID and all the other attributes remains the same.  Please let me know how to identify the elements in such scenarios.

  2. Matt
    Matt avatar
    19 posts
    Member since:
    Dec 2013

    Posted 02 Apr 2014 in reply to Vishal Link to this post

    Could you provide some sample/example code? It'd be easier to help if I could see the Html.

    You might have to get the two views as separate objects. then you can search for the one in the Edit User PopUp's DOM.

    For example (and since I don't know your code I'm just using placeholder):

    HtmlDiv addNewUser = browser.aiiBrowser.Find.ById<HtmlDiv>("Add New user");
    HtmlDiv editUserPopUp = browser.aiiBrowser.Find.ById<HtmlDiv>("Edit User PopUp");

    From there, you can then sub search each of those areas.

    HtmlSpan addNewUserInnerElement = addNewUser.Find.ById<HtmlSpan>("sharedID");
    HtmlSpan editUserPopUpInnerElement = editUserPopUp.Find.ById<HtmlSpan>("sharedID");

    That will give you the span from each of the two separate areas where the inner span is the same ID in each area, but each area has a differring ID.

  3. Ivaylo
    Ivaylo avatar
    749 posts

    Posted 07 Apr 2014 Link to this post

    Hello Vishal,

    Please note that if both elements have the same attributes this is expected behavior and Test Studio will always find the first element in the tree. In order to be able to differentiate both elements they must have something unique which the find logic of test studio will use.
    In general that's what the IDs are used for, to differentiate elements which is quite helpful in automation cases like this one. Having multiple elements with the same ID makes no sense of using an ID at all.
    The best practice of using different IDs will repay in a long term.
    If you are not able to change the IDs for the elements in the application you are using you will need to use a coded step in order to find the right element. Please check this article for more information on how you can proceed. In your case since all the attributes of the elements are the same you can use TagIndex which searches for an element using its tag name occurrence index.

    @ Matt Thanks for your input. I have updated your telerik points accordingly.

    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top