why wouldn't this XPath example work?
I am trying to locate the first <th>
element under a <table>
element. The table element is tagged with a particular id, and is locatable when I only look as far as that tag.
But when I try to go a little further down and search using the XPat开发者_如何学编程h below, it returns a null element. The '/th[0]'
is to say: return the first <th>
element, under the element that is tagged with the particular id.
In the example, the id value is populated prior to the search:
"//*[@id='{0}']/th[0]"
XPath indexes are 1-based. Try: //*[@id='{0}']/th[1]
This trips me up all the time as well; too much time spent with 0-based indexing in C, C++, etc.
精彩评论