This old post Selenium Testing Best Practices describes the problem that the id values generated by the Force.com platform on default (layout-based) UI fields vary between orgs. So the normal practice of using field ids to match page elements to stop Selenium tests being fragile (when elements are added or removed) looks impractical unless you can guarantee to only ever need to test in one org.
Can anyone offer advice on how to work around this problem?
PS I think I need to clarify the issue here. The question is not about how to use locators (or similar) in Selenium. The question is about how to insulate Selenium tests from id changes between orgs. If you use Chrome’s “Inspect Element” on a default (layout-based) UI field you will see that id values such as “CF00Nd0000005XJ71” appear. Install or deploy to a different org and that id value will have changed. I’m looking for anyone who has actually confronted this problem to share their approach to it e.g. matching other items in the pages or finding some way to abstract out the id values and use more meaningful keys in the Selenium tests.
You could try using ids in a similar fashion as how you have to use them with JQuery in Salesforce. For example, to identify the element with id
MyId you would use the identifier
j$ = jQuery.noConflict(); j$( '[id*=MyId]' ).click(myFunction);
With this in the page:
The element in the HTML Salesforce generates will be longer, but will include the one you specified.