What is XPath?
XPath (XML Path Language) is a query language for selecting nodes from an XML or HTML document tree. It is used in Selenium, scrapers, XML processors, XSLT, and browser DevTools. This XPath tester evaluates XPath 1.0 expressions with your browser’s native engine.
HTML vs XML mode
HTML mode parses markup with the HTML parser, which is forgiving and suitable for web pages. XML mode requires well-formed XML and surfaces parse errors when tags are mismatched. Pick the mode that matches your source document.
Writing effective XPath
- Prefer specific paths:
//div[@id='main']//li is clearer than a long chain of positional indexes.
- Use predicates: Filter with
[@attr='value'], [contains(.,'text')], or [position()<3].
- Mind namespaces: Prefixed XML may need local-name() tricks in XPath 1.0 when prefixes are unknown.
- Scalars matter: Wrap selections in
string(), count(), or boolean() when you need a single value.
Using this XPath tester
Paste a document, enter an expression, and review the Results panel. Node matches show type, a simple path, and a snippet. Scalar results show the typed value. Use Sample to load a bookstore XML or HTML page, and Share Link to copy a URL with your expression and mode. For related text tooling, try the Regex Tester or validate structured data with the JSON Validator.