This is a migrated thread and some comments may be shown as answers.

Unable to locate element using ID.

2 Answers 147 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vishal
Top achievements
Rank 1
Vishal asked on 02 Apr 2014, 10:31 AM
Hi,

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.

Thanks
Vishal

2 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 02 Apr 2014, 02:58 PM
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.


0
Ivaylo
Telerik team
answered on 07 Apr 2014, 07:30 AM
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.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Vishal
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Ivaylo
Telerik team
Share this question
or