# How to deal with object xpath which always changes differently

**URL:** <https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244>\
**Category:** Miscellaneous\
**Tags:** start-page\
**Created:** [April 13, 2022, 8:14am UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244 "2022-04-13T08:14:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![eugene](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/eugene/32/16104_2.png) [@eugene](https://forum.katalon.com/u/eugene)\
**Post date:** [April 13, 2022, 8:14am UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/1 "2022-04-13T08:14:22Z")

</div>

Hi all.  
Please help me with fillowing problem.  
The xpath of captured object always changing dynamically based on time of execution in milliseconds. So, every time page opening or reloading changes to object xpath.  
Example object’s xpath (Selected locator):  
//input[@id=‘sid1649833707314’]  
reload the page  
//input[@id=‘sid1649837129879’]  
reload the page  
//input[@id=‘sid1649837304629’]  
and so on…  
So, every time i execute the test, it’s fails because sid already changed  
Does anubody faces such problem. Please help

---

<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:** [April 13, 2022, 9:50am UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/2 "2022-04-13T09:50:48Z")

</div>

“Spy” and “Recorder” tools are short for Web pages with dynamic id attributes. You should not rely on them blindly.

Have a look at this advice.

> [@Support for Frameworks with dynamic Html Element Id and Name Generation (Blazor)](http://forum.katalon.com/t/support-for-frameworks-with-dynamic-html-element-id-and-name-generation-blazor/63325/2):
>
> Welcome to the forum. Be aware that Katalon Studio Web Recording is at best a “get you started” tool. When you’re faced with elements that use dynamic id attributes, you are definitely going to have issues – as you already discovered. If you use the recorder to get the test started, then you will need to edit the Test Objects in the Object Repository (OR) and “fix” the selectors used to identify the elements in your test – obviously, avoid the id attribute entirely. Alternatively, ignore the …

In most cases, you can write alternative locators without using id attribute.

In order to be able to, you need to study CSS Selector and/or XPath technology. There are some good free tutorials:

- [XPath in Selenium: How to Find & Write? (Text, Contains, AND)](https://www.guru99.com/xpath-selenium.html)

Read this article for a couple of hours, then you would soon be capable to. 😊

---

<div class="post-metadata">

**Author:** ![eugene](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/eugene/32/16104_2.png) [@eugene](https://forum.katalon.com/u/eugene)\
**Post date:** [April 13, 2022, 1:18pm UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/3 "2022-04-13T13:18:21Z")

</div>

Today i got the solution. Use CSS selector like this //input[@id^=“sid”]. This way problem solved completely

---

<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:** [April 13, 2022, 1:28pm UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/4 "2022-04-13T13:28:46Z")

</div>

> [@eugene](#):
>
> //input[@id^=“sid”].

Possibly you mis-typed this; because `//input[@id^="sid"]` is neither a valid CSS selector nor a valid XPath.

Possibly you wrote `input[id^="sid"]` as a CSS Selector.

Equivalent XPath could be `//input[starts-with(@id, "sid")]`

---

<div class="post-metadata">

**Author:** ![sjackson3289](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sjackson3289/32/16104_2.png) [@sjackson3289](https://forum.katalon.com/u/sjackson3289)\
**Post date:** [April 13, 2022, 4:23pm UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/5 "2022-04-13T16:23:13Z")

</div>

Thanks for sharing this information, I want to read more things about it!

---

<div class="post-metadata">

**Author:** ![sjackson3289](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sjackson3289/32/16104_2.png) [@sjackson3289](https://forum.katalon.com/u/sjackson3289)\
**Post date:** [April 13, 2022, 4:23pm UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/6 "2022-04-13T16:23:15Z")

</div>

Thanks for sharing this information, I want to read more things about it!

---

<div class="post-metadata">

**Author:** ![sbrod](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sbrod/32/20464_2.png) [@sbrod](https://forum.katalon.com/u/sbrod)\
**Post date:** [April 13, 2022, 6:14pm UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/7 "2022-04-13T18:14:44Z")

</div>

Personally, I try and avoid using approximate ID searches (starts with, contains, etc) because it defeats the purpose of searching by ID (IDs are supposed to be unique). It’s really dependent on your situation, and it’s also just my personal preference, but make sure that when you select an element with those kinds of operators that you can guarantee you’re selecting only the element you want and not accidentally selecting others.

For elements that have dynamic IDs, I typically try and find a static ID of a parent, child, or sibling element and use that to reference the dynamic element. Food for thought.

---

<div class="post-metadata">

**Author:** ![anon46315158](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@anon46315158](https://forum.katalon.com/u/anon46315158)\
**Post date:** [April 15, 2022, 4:32pm UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/8 "2022-04-15T16:32:35Z")

</div>

> [@sbrod](#):
>
> IDs are supposed to be unique

tell that to the development team of your AUT

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [April 15, 2022, 6:29pm UTC](https://forum.katalon.com/t/how-to-deal-with-object-xpath-which-always-changes-differently/64244/9 "2022-04-15T18:29:50Z")

</div>

ID’s can be simultaneously unique and dynamic 🙂
