Data Driven Test Automation - Test Object with dynamic IDs issue

Hi team,
I am doing data driven automation testing on Katalon Studio v9.4.5. My test case is fetching rows of data from an excel file ‘eTravel_TestData.xlsx’. In this test data file, there are 3 rows of data.

1st row of data went through the automation testing went through without any issue.
2nd row onwards, the ‘Annual’ button encountered warning error and went through self-healing.
Nevertheless, would like to resolve the error. Below are the warning error when it’s time to click the button.

2024-06-18 18:22:55.602 DEBUG .DataDrivenTest eTravel - 15: click(findTestObject(“DataDrivenTest eTravel/Page_Company/button_Annual”))
2024-06-18 18:23:26.700 INFO c.k.k.c.webui.common.WebUiCommonHelper - Unable to find the element located by ‘By.cssSelector: #mat-button-toggle-3-button’. Please recheck the objects properties to make sure the desired element is located.
2024-06-18 18:23:26.701 WARN c.k.k.c.webui.common.WebUiCommonHelper - [SELF-HEALING] Failed to find element with id ‘Object Repository/DataDrivenTest eTravel/Page_Company/button_Annual’. Try using Self-healing.
2024-06-18 18:23:27.056 WARN c.k.k.c.webui.common.WebUiCommonHelper - [SELF-HEALING] The current locator of test object ‘Object Repository/DataDrivenTest eTravel/Page_Company/button_Annual’ was broken. Propose an alternative one: ‘(.//*[normalize-space(text()) and normalize-space(.)=‘Single’])[1]/following::button[1]’.

In Katalon, the object name is ‘button_Annual’. Below is the script.

WebUI.waitForElementClickable(findTestObject('DataDrivenTest eTravel/Page_Company/button_Annual'), 5)'DataDrivenTest eTravel/Page_Company/button_Annual'))

From the web browser, I have captured the elements’ detail as follow. Noticed the elements have dynamic IDs, changes everytime when the same button re-visited.

Below image is the details on the ‘button_Annual’ object in Katalon Object Repository.

Would like to seek help on how to fix the dynamic IDs issue and sample guidance on how to update into the object ‘button_Annual’.

Many thanks in advanced.

1 Like


Thank you for your thorough explanation of your problem. I hope that all of the questioners here should post their questions in the way as you did.

Your Test Object “button Annual” currently has the following locator:


I suppose that this locator was generated by the Spy or Web Rcording tool built-in Katalon Studio. These tools are … what to say … not very intelligent. But you shouldn’t blame the tools. You should embrace the tools. They do help us getting started with automated UI testing by generating a bunch of Test Objects as materials. You can manually improve the generated locators.

You, a human, are intelligent enough. You can comprehend an id value "mat-button-toggle-3-button" and parse it into 3 portions in your mind:

  • mat-button-toggle-
  • 3
  • -button

The first and the last string portions will certainly be static; only the middle portion ("3") will move dynamically.

Now you can manually edit the generated locator string so that it intentionally ignores the dynamically moving portion in the id value, like:

//button[starts-with(@id, 'mat-button-toggle-') and contains(@id, '-button')]

This locator will be tolerant of any values as follows:

  • mat-button-toggle-3-button
  • mat-button-toggle-13-button
  • mat-button-toggle-23-button.

Possibly you would also want to rename the Test Object from "mat-button-toggle-3-button" to something more generic; for example "mat-button-toggle-X-button".

1 Like

Or use the CSS equivalent with partial CSS selectors Begins with (^=) and Ends With ($=) combined.


1 Like