Ramesh
Ramesh

Reputation: 11

Index value of object in QTP

I have two question. 1) just assume that we 5 object in webpage.then how will find out index value of those object in run time. 2) suppose in next release , if the index gets changed, our code definitely will fail.so in this case how to write code. is there any logic to overcome this issue without changing code offen?

Upvotes: 0

Views: 2642

Answers (2)

jeff m
jeff m

Reputation: 275

What kind of objects are they? Index is usually a terrible way of going about identifying/manipulating objects imo. Adding the objects as tables and testing with the child items might be a better solution.

Upvotes: 0

AutomatedChaos
AutomatedChaos

Reputation: 7500

In my experience, the index of webelements is always in the same order as they appear in the DOM. Keep in mind that the amount and the location of webelements int the DOM is dynamic and can be different than the source you can obtain through "view page source".

When the index is the only unique identifier and the index changes, you have to change the code. Try to find unique identifiers other then Index or a combination of identifiers to make it unique. It prefers to use html id if available, because that should be unique, but also innerhtml or outerhtml can be good options.

If non of this is achievable and testautomation is an important item within your company, you should talk to your developers (when the software is created in house of course). Explain what you are doing (they will be interested, they are the solution freaks of your company you know) and explain your problem and if they can help you out. Let one of them come up with the idea to add an id to each html object et voila, problem solved.

Upvotes: 1

Related Questions