tags:

views:

373

answers:

4

We can search for specific field on website in a few ways: based on css, name, id, structure, even any text found. Which way have you decided to use?

What would be best practice for it?

Edit: I'm asking from developer perspective: How to write code that it will be easier to test with Selenium by one method (that is: being able to search all of them by it's name)

+2  A: 

We generally stay away from xml structure, which turns out to generate way too fragile tests. Our internal organization makes CSS names off-limits, since that is for the design people to manipulate. You don't want your tests to break because someone changes style from heading1 to heading2.

We have opted for a solution that is mainly based on id's. Sometimes we even instrument the HTML with id's just to be able to selenium test.

Additionally we also look for texts (application texts), but internationalization makes this a bit of a pain; we have made our test fixture locale aware.

krosenvold
+1  A: 

ID is almost always the best if you can remember to do it.

Patrick Lightbody
+1  A: 

I tend to favour XPath expressions looking for 'id' or 'name' attributes.

However, if you execute your tests in IE6 regularly, beware of using XPath for locator expressions. XPath runs noticably slower in IE6 compares to later versions or Firefox. I've got a rather large SeleniumRC test suite that takes upwards of three hours to complete with IE6, compared to an hour with Firefox.. (all of that time isn't caused by the XPath, but it does contribute significantly).

Peter Bernier
+1  A: 

After a while I have discovered other option: create your own attribute and build javascript function for Selenium IDE to generated xpath based on this attribute. That wasn't that hard :)

It makes generating and maintaining tests so much easier (when suddenly span become div ;) )

Ula Karzelek