Xpath question:
When to use @ with an attribute and when not to. Does it matter? What is the difference
Xpath question:
When to use @ with an attribute and when not to. Does it matter? What is the difference
If you are referring to an attribute, you must use @
, otherwise you are referring to an element of that name!
When using //tag[attr]
you are selecting all tag
elements that have at least one child element named attr
. On the other hand, when using //tag[@attr]
you are selecting all tag
elements that have an attribute named attr
.
In sum, you use @
everytime you want to select an attribute. It does matter, because omitting it would select nodes or elements, instead of attributes.