开发者

Reproducible way to ID an element on a page

An interesting problem:

I want to have a reproducible way to identify elements on a page such that I can store this ID and be able to id the element on another client, without having to store the full HTML. It needs, also, to be robust to insertion / removal of nodes in the DOM (so a simple numbering convention will not work).

So far, Im thinking: In certain cases we will have a unique id which i can use, falling back to offset from the first parent that does have an id attached, else parent that has a class attached. Does this make sense? Am I missing a开发者_StackOverflow中文版 trick?

Kind of related: What information about a DOM element would allow JavaScript to identify it (somewhat) uniquely? (e.g. when it doesn't have `id`)


If I understand your question, you want to know a robust XPath () for any element An ID would be a Base64 version, or a hash version of the XPath of the element

That question sounds a bit weird to me, no offense. If you don't functionnally or semantically define each element in the DOM, what identify it is precisely its position in the DOM, or if you want the relationship it has with other element in the DOM...

The fifth row of a table could have a functional definition (depending on the application, eg in a mail box app, its something like ), but it can also be the fifth element of a table... The information about the element is made by the intent of the developer, not by a magic formula describing every html element ever made

Correct me If I misunderstood your point

Cheers

Grooveek

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜