Alertcat

XPath tester

Paste HTML, type an XPath expression, and see what it returns. Nothing leaves your browser.

What this tool does

XPath is a query language for documents. It can walk up and down the page tree, match on text, and count things, which CSS selectors cannot do. This tool parses your pasted HTML and evaluates an XPath 1.0 expression with the browser's built-in engine.

The result depends on the expression. A path such as //h2 returns nodes, shown with their markup. A function such as count(//li) returns a number. string(//title) returns text, and boolean(//button) returns true or false.

How it relates to Alertcat filters

Alertcat accepts XPath as a filter. Start the filter with xpath: so Alertcat knows it is not a CSS selector. Only the matched nodes are kept for comparison.

Pick XPath when CSS is not enough. Examples: the cell next to a label (//td[text()='Price']/following-sibling::td), the first item with a given word (//li[contains(., 'Sale')]), or the parent of a known element. Because XPath 1.0 has few functions, it stays predictable.

As with CSS, Alertcat only sees the HTML returned by the server. If a script adds the content later, it is not available to the filter yet.

Using the result in a watch

  1. Paste the HTML source and an expression, then press Test XPath.
  2. Check the count and the first results. Narrow the expression until it returns only what you want.
  3. In the watch, add the expression to the XPath filter field with the xpath: prefix.
  4. Save, run a check, and compare the preview with what you saw here.

Frequently asked questions

Does it support XPath 2.0 or 3.0?

No. Browsers implement XPath 1.0, and that is what this tool tests.

Why do I get no results on a page that has the element?

HTML parsers add tags such as tbody and may lowercase names. Use a looser path like //td instead of a long absolute path.

Should I use XPath or CSS?

Use CSS when a class or id is enough. Use XPath when you need text matching or relations that CSS lacks.

Test an XPath expression

Related

Watch the pages that matter

Alertcat is in early access. Tell us what you want to watch and we will set up your team.

Request access