开发者

why wouldn't this XPath example work?

开发者 https://www.devze.com 2022-12-17 05:01 出处:网络
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.

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.

0

精彩评论

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

关注公众号