To be more specific, I'm studying a use case where an automation would be preferable instead of just passing it to a user (for QA an acceptance). On the Lightning Experience interface, however, I've hit a quite challenging obstacle: CSS selectors.

I noticed that the default "new case" window, for example, contains some picklist fields which do not have unique IDs to be easily found by the automated tool. A picklist field's div show up like this:

<div data-aura-rendered-by="7477:0" class="uiMenu" data-aura-class="uiMenu">
    <div id="7451:0" data-aura-rendered-by="7458:0" class="uiPopupTrigger" data-aura-class="uiPopupTrigger" data-interactive-uid="21">
        <div data-aura-rendered-by="7460:0" id="7460:0">
            <div data-aura-rendered-by="7453:0">
                <a aria-required="false" class="select" aria-disabled="false" aria-describedby="7444:0-label" aria-haspopup="true" tabindex="0" role="button" title="" data-aura-rendered-by="7454:0" href="javascript:void(0);" data-interactive-lib-uid="26">-- None --</a>

As you can see, there are ids, but they are all global ids generated by Salesforce at runtime. It is impossible to use them on the tests since they can change.

It would be awesome if we could get the field's API name in a div attribute, for example.

Are there any tips to overcome this issue with automated testing?


Use a two step process:

  1. Get all the IDs using one of the API methods which matches the element type
  2. Filter by the other metadata unique to the element you are targeting

For example:

If however, you do need to use the ID to locate the element, a different solution is needed. You can capture this ID from the website before you use it in a Selenium command. It can be done like this.

String[] checkboxids  = selenium.getAllFields(); // Collect all input IDs on page.

for(String checkboxid:checkboxids) {
    if(checkboxid.contains("addForm")) {



  • But how do you get the ID that is generated by the platform on standard pages? Like on a record creation, for example. That's what this question is about. Lightning Components on the other hand are easily tested. Jan 1 '19 at 23:07
  • //*[@id] would be the simplest way to do it. Assuming Selenium, you need to account for async before looping through the elements. Jan 1 '19 at 23:46

As Paul mentioned, you should build UI tests with a library such as Selenium and Webdriver.io. However, an important limitation of these type of tests is that they are tightly coupled with the DOM. If you or Salesforce introduces changes with a new release, you'll have to maintain your tests.

I recommend that you take a look at the UTAM pilot. This pilot aims to address the difficulty of maintaining UI tests that are tightly coupled with the UI and the DOM in particular.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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