I just started with Saleforce/Force.com development. I set up a couple of Selenium tests last week, but they crashed today, since Salesforce upgraded to Version Winter '14 on my Dev Sandbox. My Selenium tests rely on the id-tags within the DOM, which now have other numbers.

I would like to know on which DOM elements you guys rely on to run Selenium tests?

2 Answers 2


Are you using Selenium IDE or Selenium Webdriver?

I'm using the latter and match Salesforce Ids using css selectors - if your visualforce is annotated with Ids then your id will always appear at the end of the salesforce generated Id. For example:

A visualforce entry like this:

<apex:inputField id="accountName" value="{!CustomObjectX__c.Account__c}" required="true">

Will be rendered as this mess:

<input id="j_id0:j_id1:TheForm:j_id77:j_id78:j_id79:accountName" maxlength="255" name="j_id0:j_id1:TheForm:j_id77:j_id78:j_id79:accountName" onchange="A4J.AJAX.Submit('j_id0:j_id1:TheForm',event,{'similarityGroupingId':'j_id0:j_id1:TheForm:j_id77:j_id78:j_id79:accountName:j_id82','parameters':{'j_id0:j_id1:TheForm:j_id77:j_id78:j_id79:accountName:j_id82':'j_id0:j_id1:TheForm:j_id77:j_id78:j_id79:accountName:j_id82'} ,'containerId':'j_id0:j_id1:TheForm:j_id77:j_id78:j_id79:j_id81'} )" size="20" type="text" value="The Account Name">

meaning you can reference the component using the following css selector:


(An input that has an id which ends with accountName - signified by the $=)

This will then match in any org your code is deployed to. Using selectors gives you more flexibility too, you can match on other attributes of the rendered html. Take a look at CSS selectors for Selenium which gives a good starting overview and also covers how to use such selectors if you are using Selenium IDE


I would stay away from using ID tags for automated testing, if you are testing a VF page you can use the class name instead.

  • What would you recommend then for a test using/requiring standard pages? Button or link values (such as "Edit" or "Save") or something else?
    – Mike Chale
    Commented Sep 9, 2013 at 12:39
  • I was thinking about using class names as unique identifiers, but I do not have access to it - yet. For now I use XPath Queries and I hope that the DOM wont change. Commented Sep 9, 2013 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .