I have heard as well as followed concept of keeping UI objects in external filed (xml or properties files in java). But there are times when I need to keep the objects with in test because I use them dynamically.

For example consider one html table with div having uniquq id. The div could have n number of links. I need to read their innertext. So I would be doing -

for(int i=0; i<=CSSCount(div[id='unique']>a);i++) {


So I have app object available in test class it self, that is - css=div[id='unique']>li:nth-child(i) as I need to iterate through its elements. Is it possible to externalize such app objects also?

2 Answers 2


Apart from stuartf's comment, I would suggest an approach where when you want to implement things like "as I need to iterate through its elements" to implement them on a generic method and not inside the Test class so as to reuse it (and then it is dynamic).

  • Yup I do that, in fact I follow page object model and keep page interaction module out side test.
    – Tarun
    May 11, 2011 at 2:53

What you want to do here is change the approach to finding the object, rather than finding the object by id add a consistent class attribute to the each of the divs that you are interested in and find by class rather than the id attribute.

for(int i=0; i<=CSSCount(div[class='row']>a);i++) {

Then you can place the 'row' attribute or whatever you decide to call it in a external resource file.

Hope this helps!

  • actually I was talking about externalizing entire object that would be - css=div[class='row']>a:nth-child(i)
    – Tarun
    May 11, 2011 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.