Find your content:

Search form

You are here

How to handle non-Visualforce field ids in Selenium tests?


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.

Attribution to: Keith C

Possible Suggestion/Solution #1

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.

Attribution to: ceiroa
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content