I have this piece of HTML codes
I need to find those 2 objects using JavaScript so I can click() it and write some text (Test Automation).
The issue is the id is dynamically generated, thus can't be used because it keeps changing everytime the page loads. Now because the id can't be used , those 2 objects looks the same without any unique identifier.
If I use this
document.querySelector("input.value-restored[type='text']");
Then it will just find the first one.
Any idea how can I hit both objects?
Thank you.
You can use
[contains()]
to construct a xpath for these elements. As I can see the parentspan
has a stable class name which you can use.in JAVA
OR use indexing with your xpath.
Hope this helps.
In TestComplete, you can do this in the following way (within script):
If you are using Name Mapping, you can map this object quite reliably using the Required Children feature and access the object directly by a name from the mapping tree. Let me know if you need more details on how to create such mapping.
Try this way.
Use indexing after complete your xpath. Inside below xpath
[2]
indicates secondinput
webelement. If there are multiple input tag is available then you should use of indexing.If you want to locate first webelement then use below xpath.