[KShare] How to automatically create unique Salesforce Object locators using Katalon Object Spy

Salesforce Testing can be a little tough sometimes due to the way Salesforce handles its HTML DOM for websites. A Salesforce website has Standard Objects as well as Salesforce custom objects, and using Katalon Studio, we can capture and select the best possible locator strategy for them. Using Katalon Studio and its features can surely ease and smooth up the process of Salesforce automated testing.

1. How can we efficiently use the Inbuilt Katalon Studio feature: Object Spy to capture unique locators for a Salesforce object?

We can capture a Salesforce object and its locator strategy using Katalon Studio’s built-in feature, Object Spy. When the Object spy captures an object, it captures all of the possible locators for an object, including static and dynamic locators. But due to the way Salesforce handles HTML within their web, it needs us to select some particular object’s locators and verify if they are unique or not.

We can select the Salesforce object locators using Object Spy and finalize the one that we want to use. We can also verify whether that locator is unique to a particular object or not and if yes, then which one.

2. Steps to capture and verify a unique locator for a Salesforce object

In this tutorial we will show how you can we automatically create Salesforce object locators using automation testing tools like Katalon’s Object Spy.

  1. Open Katalon Object Spy and input your Salesforce URL and Click on Spy Object

  1. Navigate to the Salesforce object that you want to capture, then Right click on it > Select Capture Object

  1. After you have captured the object/element, Katalon Studio will gather all the possible locators for that Salesforce object, related to the object’s Xpath, attributes, CSS, etc.

    a) You can select your preferred locator strategy from all the selected locators, please refer to the below image:

  1. Now, after you select your desired locators, there is a way to verify if those locators uniquely define your selected Salesforce object or not:

    a) After selecting your desired locator, please click on “Verify and Highlight“. This will highlight the elements with that locator strategy and may provide you with any one of the below scenarios:

    i. “Found 1 element using SELECTED locator“: This means that with your SELECTED locator, Katalon has detected one single element making that locator as a “Unique locator“.
    ii. “Found N elements using SELECTED locator“: This would mean that with your selected locator strategy, we have identified several (N number of elements) elements. These N elements have the same locator.

  1. After verifying that your locator is unique for your Salesforce object, you can save and proceed ahead to use that object in your scripts.

3. External extensions to help you to capture unique locators when testing with Salesforce

Now, Katalon Studio has the functionality to capture almost all possible and the best locators for an object, but due to the way Salesforce handles the HTML DOM within their website, we can also opt to use some external extensions that can be used to automatically get some unique locators for those elements.

3.1. Steps to use other extensions

3.1.1. Chrome Developer Tools

  1. Right-click on the Salesforce object of which the locator you want to capture and click on “Inspect”
    2.Right-click on the HTML of that element and hover over “Copy”
  2. Select your preferred locator strategy which will copy the locator value for you.

To verify if you have done it right, you can use the Chrome Inspect Tool:

  1. (Only in the context of Google Chrome) Right-click on the element and then open “Inspect”
  2. On your keyboard, press Command + F (MacOS) or Ctrl + F (Windows).
  3. This will open anew input box where you can input the generated locator and verify if it is unique to a single element or not.

3.1.2. POM Builder

  1. You can download this extension for Chrome and Edge from here: POM Builder
  2. After downloading this extension, please open your website and the right click on the object/element that you want to capture.
  3. This will automatically copy the locator for you.

  1. To verify the uniqueness, you can follow the same steps as done for “Chrome Developer Tools”.

With the steps above you can surely ease and reduce the manual work in Salesforce automation testing with Katalon. If you find this article helpful, then don’t hesitate to give us a big like :+1: or show us your love :heart: !


Thank you the @support.squad and @bhavyansh.ameta for this incredibly detailed articles on Salesforce and Katalon!

Bhavyansh Ameta (@bhavyansh.ameta) - Junior Product Support Specialist
Bhavyansh is a Junior Product Support Specialist at Katalon who utilizes his technical expertise to assist users with intelligent solutions. His passion for delivering exceptional support is not just about providing answers but fostering a positive and empowering user experience.

This is Part 2 of our Salesforce-focused series in January 2024. To read the other articles within this series, you can go to the topic below …

or navigate to the support tag.