5

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.

1
  • What Selenium library are you using? And what sorts of configurations are you trying to do? Commented Nov 19, 2012 at 21:20

1 Answer 1

2

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.

1
  • 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. Commented Nov 19, 2012 at 21:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.