How to deal with object xpath which always changes differently

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

“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.

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:

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

1 Like

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

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")]

1 Like

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

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

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.

1 Like

tell that to the development team of your AUT

ID’s can be simultaneously unique and dynamic :slight_smile: