# Data Driven Test Automation - Test Object with dynamic IDs issue

**URL:** <https://forum.katalon.com/t/data-driven-test-automation-test-object-with-dynamic-ids-issue/135133>\
**Category:** Web Testing\
**Tags:** dynamic-id, self-healing\
**Created:** [June 19, 2024, 5:07am UTC](https://forum.katalon.com/t/data-driven-test-automation-test-object-with-dynamic-ids-issue/135133 "2024-06-19T05:07:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emlearn](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/emlearn/32/23870_2.png) [@emlearn](https://forum.katalon.com/u/emlearn)\
**Post date:** [June 19, 2024, 5:07am UTC](https://forum.katalon.com/t/data-driven-test-automation-test-object-with-dynamic-ids-issue/135133/1 "2024-06-19T05:07:19Z")

</div>

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.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/b/0/b0992b03a78bb67c532782e2ec558afdcbb71e5b.png)

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)

WebUI.click(findTestObject('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.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/3/4/34de2b97502af4dd287c2247aee6de0dbcb2c804.png)

Below image is the details on the ‘button\_Annual’ object in Katalon Object Repository.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/7/a/7a102510b9076c7437edb3d6305c542d51daa15e.png)

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.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 19, 2024, 12:32pm UTC](https://forum.katalon.com/t/data-driven-test-automation-test-object-with-dynamic-ids-issue/135133/2 "2024-06-19T12:32:50Z")

</div>

@emlearn

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:

```auto
//button[@id='mat-button-toggle-3-button']

```

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:

```auto
//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"`.

---

<div class="post-metadata">

**Author:** ![Kat-User-3000](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kat-user-3000/32/23870_2.png) [@Kat-User-3000](https://forum.katalon.com/u/Kat-User-3000)\
**Post date:** [June 19, 2024, 3:00pm UTC](https://forum.katalon.com/t/data-driven-test-automation-test-object-with-dynamic-ids-issue/135133/3 "2024-06-19T15:00:46Z")

</div>

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

[id^=”mat-button-toggle-“][id$=”-button”]
