I want to check the structure of some html piece of markup, just checking the structure.
For example I need to check that SOMEWHERE in <list-item-canvas> tag is <image name='category-pic'> tag.

I write:

//div[@class='list-item-canvas'][1]/*/img[@name='category-pic']

That's working if <img> is a second node after any ('*') node in the hierarchy, BUT if I have <img> somewhere deep-deep in the structure, AND I do not want to care about the level hierarchy how then I should write my xpath-query? I would think that instead '*' I might write '**' but I can not..

2 Answers
2

This selects any img the string value of whose name attribute is 'category-pic' and that is a descendant of the first (in document order) div the string value of whose class attribute is 'list-item-canvas'.

Do note the bracets surrounding the subexpression:

(//div[@class='list-item-canvas'])[1]

this is quite different from:

//div[@class='list-item-canvas'][1]

the latter selects everydiv element in the document that is the first div child of its parent -- and there may be potentially more than one such elements.