Currently working on an issue where I need to be able to quickly, and accurately identify each element within an HTML DOM. The problem is that I do not have the ability to interact with any of the server side or client side javascript, so I cannot simply add IDs to elements. The site can also be dynamic (like a react app) so elements may be added/removed/moved throughout the session, making this quite difficult. I am able to add scripts on top of the app, but not modify what is already there.
I thought using some combination of XPath and HTML attributes would work, but overall the solution seems very messy, and not 100% accurate. For example, in the HTML snippet below, it is not possible (to my knowledge) to uniquely identify the div elements in the tree.
<head>
<div>hello</div>
<div>world</div>
</head>
An XPath search of "/head/div" would return both divs, and since they have no attributes, there is no way to uniquely identify one or the other.