XPath yourself: Tips & Tricks
summary
Concrete, practical rules for writing more reliable XPath selectors: use explicit axes (e.g., ancestor::, following::) instead of chains of .. or //, avoid absolute paths, and prefer child predicates like div[1] rather than global grouping ((//div)[1]) because they have different position semantics. Use functions position(), last(), contains(text(), ...) and normalize-space() for resilient matching, be careful with the predicate-ordering quirk when combining numeric positions and filters, and compute table column/index positions with count(preceding::*)+1 instead of hardcoding numbers.
AI-written summary · about
chapters (10)
- 0:00XPath introduction
- 1:05XPath as query language
- 3:13Full vs abbreviated XPath
- 5:23Parent vs ancestor axes
- 7:54Stable queries with axes
- 10:21Absolute path issues
- 12:07Text and content search
- 14:14Position functions
- 15:39Position/last filtering errors
- 17:46Tables and dynamic elements








