# Get the Id dynamic for doing a test

**URL:** <https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843>\
**Category:** Web Testing\
**Tags:** katalon-recorder\
**Created:** [May 17, 2021, 7:17am UTC](https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843 "2021-05-17T07:17:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amadese](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/amadese/32/21141_2.png) [@amadese](https://forum.katalon.com/u/amadese)\
**Post date:** [May 17, 2021, 7:17am UTC](https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843/1 "2021-05-17T07:17:42Z")

</div>

Hi,

I’m trying to do a test on a page containing several div with a dynamic id.  
I don’t know how to do the test based on the dynamic Id.

When I tried that:  
Command: `asertText`  
Target: `//div[@id='mat-menu-panel-53']/div/span[2]/span/ux-dropdown-button-item/div/button`  
Value: `My Text`

It’s correct and working but when the user reloads the page the Id changes (for instance 53 is replaced by 60) and the test can not be performed.  
Is it possible to look the div with the Id starting by “mat-menu-panel”. Which command and target I have to use?

Thanks in advance for your help

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [May 17, 2021, 8:42am UTC](https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843/2 "2021-05-17T08:42:14Z")

</div>

Hi, please try the following target:

`//div[starts-with(@id,'mat-menu-panel-')]/div/span[2]/span/ux-dropdown-button-item/div/button`

---

<div class="post-metadata">

**Author:** ![amadese](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/amadese/32/21141_2.png) [@amadese](https://forum.katalon.com/u/amadese)\
**Post date:** [May 17, 2021, 8:59am UTC](https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843/3 "2021-05-17T08:59:51Z")

</div>

@ThanhTo Thanks it’s working. Nevertheless when I call a form, I have several fields. But when I select the field in the Katalon Recorder tool (for the target), the target is `id=ux-form-control-695730` and I obtained the same issue when the form is called again. The id will change. Do you know another way for calling correctly the target ?

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [May 17, 2021, 9:01am UTC](https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843/4 "2021-05-17T09:01:26Z")

</div>

@amadese

You can try to choose another locator for the target. Next to the target field there’s a drop-down where you can select available locators. You should choose a locator that doesn’t use ID.

---

<div class="post-metadata">

**Author:** ![amadese](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/amadese/32/21141_2.png) [@amadese](https://forum.katalon.com/u/amadese)\
**Post date:** [May 17, 2021, 10:36am UTC](https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843/5 "2021-05-17T10:36:41Z")

</div>

@ThanhTo is it possible to work with another attribute “formcontrolname” of the field rather that the “id” ?

```
<div>
<ux-form-control _ngcontent-jol-c274="" formcontrolname="creditTypeId" _nghost-jol-c180="" class="ng-untouched ng-pristine ng-valid">
<select _ngcontent-jol-c180="" class="ux-form-control ux-form-control__custom-select ng-untouched ng-pristine ng-valid ng-star-inserted" id="ux-form-control-562878" data-e2e="ux-form-control-sel-rw" tabindex="0" aria-required="false" aria-invalid="false">
<option _ngcontent-jol-c180="" value="1" class="ng-star-inserted"> Operational credits </option>
<option _ngcontent-jol-c180="" value="2" class="ng-star-inserted"> Administrative credits </option>
</select>
</ux-form-control>
</div>

```

Thanks

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [May 17, 2021, 12:16pm UTC](https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843/6 "2021-05-17T12:16:47Z")

</div>

Try something like this: `//*[formcontrolname="creditTypeId"]`.

---

<div class="post-metadata">

**Author:** ![1968693027](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/1968693027/32/18174_2.png) [@1968693027](https://forum.katalon.com/u/1968693027)\
**Post date:** [June 2, 2021, 3:38am UTC](https://forum.katalon.com/t/get-the-id-dynamic-for-doing-a-test/54843/7 "2021-06-02T03:38:56Z")

</div>

> [@ThanhTo](#):
>
> //div[starts-with(@id,‘mat-menu-panel-’)]/div/span[2]/span/ux-dropdown-button-item/div/button

我一般是这样做的 //div[contains(@id,‘mat-menu-panel-’)]/div/span[2]/span/ux-dropdown-button-item/div/button
