Google recently posted an article on their testing blog: Survival techniques for acceptance tests of web applications (Part 1). In it they note the difference between various expressions used with Selenium to get access to an object on a web page:
For each method, we need to work out how to implement it in code. How could an automated test select the compose message icon? Do alternative ways exist? An understanding of HTML, CSS, and JavaScript will help you if you plan to use browser automation tools. All the visible elements of a web application are reflected in the Document Object Model (DOM) in HTML, and they can be addressed in various ways: the directions from the root of the document to the element using xpath; unique identifiers; or characteristics possessed by the elements, such as class names, attributes, or link text. Some examples of these addressing options are shown in the Navigation Options illustration below. (Notes: navigation using xpath is much slower than using IDs; and IDs should be unique.)
We agree that IDs are usually the best approach, but sometimes (especially with AJAX.NET applications) those IDs are actually really bad to use. The reason is that some frameworks (AJAX.NET, ExtJS, etc) use ID generation techniques that aren’t the same for every page view or every web app build.
As such, keep an eye out for suspicious IDs and be prepared to switch back to XPath or DOM locators when necessary. For example, if you see an ID like ctl00_ctl00_cp_cpTab_txtFirstName (generated from AJAX.NET) consider changing it to an XPath such as //input[contains(@id, 'txtFirstName')].
Related to that topic, they also note that scripts recorded in Selenium IDE should not be considered “done” and will likely need to be optimized and tweaked before they can be considered stable:
The open-source test automation tool Selenium (http://seleniumhq.org/) includes a simple IDE record and playback tool that runs in the Firefox browser. Recorded scripts can help bootstrap your automated tests. However, don’t be tempted to consider the recorded scripts as automated tests: they’re unlikely to be useful for long. Instead, plan to design and implement your test code properly, using good software design techniques.
The author goes on to suggest Firebug as a great tool for doing this kind of work, which we tend to agree with and have covered previously. But they missed one of the most important functions: the ability to easily test XPath expressions from within Firebug!
Very few Firebug users know about this, so take note: Firebug adds a $x function that can be called from the console. It takes an XPath in the form of a String and will spit out the HTML elements that it evaluates to directly back in the console. You can then mouse over the elements and check that the XPath is working correctly:

Armed with Selenium IDE, Firebug, and $x function, you should be able to build out solid Selenium scripts in no time!
Shameless plug: these types of tips (and more) are yours for free when you sign up for a BrowserMob performance and load testing account.




FireBug’s indispensable for Selenium (or Watir/Firewater/etc.) testing!
I also use XPather and XPath Checker, both add-ons for FireFox. Complex XPath can be such a pain that sometimes my brain just works better flipping to a different tool when trying to solve a complex XPath.
I always use the Find button from Selenium IDE, it’s very useful for checking any locator I’ve written.
Selenium with EXTJS has issues when it comes to Combo Boxes and Grids. As of yet, they appear to be un-testable.
Hi,
I am struggling to fix this problem i have selenium IDE generated code
//div[@id='ext-gen25']/div[10]/table/tbody/tr/td[2]
In this ext-gen25 is dynamically changed to ext-gen29, ext-gen45 for each run. How can i use XPATH to locate this each time correctly.
Thanks,
Basham
Not being able to see HTML tab of Firbug while writing on console makes it tough when using $x function.
I would prefer Selenium IDE, or FF plug-in XPath checker which let me see HTML tab of Firebug
@Tarun Firebug 1.6.0 added the console to all tabs. There’s a notepad like icon (box with 3 horizontal lines) that opens the console below the html/css/script/dom windows.
Thank you very much — this is little function has been a BIG help to my testing.
Hi,
We are trying to automate CRM application which is based on GXT (extended GWT – Google Web Tool Kit) technology using Selenium IDE. After recording, when the Test Case is run through Selenium IDE, it is not able to recognize that object. We have also tried using Xpath: //input[@span='Device']
When verified through firebug, below is the HTML code:
Device
Can somebody suggest a remedy for the same?
Thanks & Regards,
Anurag
how to select values from combo box in selenium ide using ajax application can any one help me out
Guys.. Did anyone try testing TreeGrid component with selenium. I hardly see any help on this or people sharing their success stories on automating TreeGrid.
Any help is appreciated!