Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This old post Selenium Testing Best Practices describes the problem that the id values generated by the 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.

share|improve this question
What Selenium library are you using? And what sorts of configurations are you trying to do? – jordan.baucke Nov 19 '12 at 21:20

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 [id*=MyId]:

j$ = jQuery.noConflict();
j$( '[id*=MyId]' ).click(myFunction);

With this in the page:

<div id="MyId">...</div>

The element in the HTML Salesforce generates will be longer, but will include the one you specified.

share|improve this answer
Might want to try: j$('[id$=MyId]') which only returns results that end with the Id instead of containing that 'MyId' string. That being said, I don't think locating elements with JS in Selenium is considered best practice, but might be the only solution in Salesforce where the XPath and Id's can change all the time. – jordan.baucke Nov 19 '12 at 21:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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