XPath & CSS Selector Tester
Run XPath and CSS selectors on your own XML or HTML, and click a node to get its path.
Try before you buy.
- Free preview: every match counted, with the first matches (up to 10) listed and marked in your document, and the type of any number, text or true/false result.
- Locked until you unlock it: download and copy.
- Unlock: Pro pass, ₹179 for 30 days or ₹79 for 1 week, a one-time payment that never renews. Unlock: Pro pass, $5.99 for 30 days or $2.99 for 1 week, a one-time payment that never renews.
Ways to unlock shows how to get the full result.
Printing this result is locked in the free preview.
Results update as you type. XPath 1.0 is what browsers, Selenium and most scrapers run.
Namespaces
Matches
Selected node
Document view
Locked in the free preview. Opens the ways to unlock this result.
Locked in the free preview. Batch runs unlock with a pass.
Locked in the free preview. Query results unlock with a pass.
About the XPath & CSS Selector Tester
Paste XML or HTML and test XPath 1.0 expressions or CSS selectors against it. Every match is highlighted in a readable view of the document and listed with its value — the text of an element, the value of an attribute — and expressions that return a number, a string or a true/false value show that result. The browser’s own engines run the expressions, exactly as document.evaluate() and querySelectorAll() see them — and so as browser-driven tools such as Selenium, Playwright and Puppeteer do.
Click any element, attribute or piece of text in the document to get an absolute XPath that selects exactly that node and a CSS selector for it. Namespaces are handled: prefixes declared in the document are mapped automatically, the default namespace gets a prefix of your choice (the classic reason //book finds nothing), and you can add mappings of your own. When an expression fails, the message says why, including the XPath 2.0 functions people often try and what to write in XPath 1.0 instead. Nothing you paste leaves your browser.
Without a pass you see a free preview: every match counted, with the first matches listed and marked in your document, and the type of a number, text or true/false result. A Pro pass unlocks every match and value, the XPath and CSS selector of any node you pick, Copy, Test this XPath and the CSV download.
How to use it
- Paste the XML or HTML into the document box, open a file, or load a sample. XML or HTML is detected; you can choose it yourself.
- Choose XPath 1.0 or CSS selector and type the expression. Results update as you type.
- Read the matches: each is highlighted in the document view and listed with its value; Show scrolls to it.
- For namespaced XML, use the prefixes listed under Namespaces — the default namespace is mapped to
dunless you choose another prefix — or add your ownprefix=URIlines. - Click any node in the document to get its absolute XPath and a CSS selector; with a pass, or after unlocking them, copy them or press Test this XPath.
Examples
//d:book[@category='programming']/d:title
Learning XPath Selectors in Depth
The sample catalog has a default namespace, so its elements need a prefix: here d, mapped to urn:example:catalog.
sum(//p:price[@currency='EUR'])
64.45
li.product:not(.sold-out) .name
Desk lamp Monitor arm
Run as a CSS selector.
//a[ends-with(@href, '.pdf')]
Not valid XPath 1.0 — ends-with() is XPath 2.0. Write substring(@href, string-length(@href) - 3) = '.pdf'.
Common uses
- Writing and debugging XPath or CSS selectors for web scraping, Selenium, Playwright or Cypress tests.
- Querying SOAP responses, RSS and Atom feeds, sitemaps, SVG, Office XML or any other XML with namespaces.
- Getting a stable path for an element of a page to use in monitoring or an extraction rule.
- Checking a value in a large XML configuration or data file without writing code.
- Learning XPath: axes, predicates and functions, with immediate results.
XPath 1.0 in brief
- Paths:
/starts at the document,//searches at any depth,.is the current node and..its parent;@idis an attribute,text()text,*any element. - Predicates filter in square brackets:
//book[2](the second),//book[@id="b1"],//book[price > 30],//li[last()]. - Axes walk in other directions:
ancestor::,following-sibling::,preceding::,parent::,descendant-or-self::. - Functions (W3C XPath 1.0):
count(),sum(),contains(),starts-with(),normalize-space(),translate(),substring(),string-length(),concat(),local-name(),not(),position()and a few more. There are no regular expressions, noends-with(), nolower-case()— those came with XPath 2.0. - Results are a node set, a number, a string or a boolean:
count(//book)gives a number,//booknodes.
Why //book finds nothing: the default namespace
When the root says xmlns="urn:example:catalog", every unprefixed element is in that namespace — and in XPath 1.0 a name without a prefix only matches elements in no namespace. So //book matches nothing. Map the namespace to a prefix and use it (//d:book; this tool maps the default namespace to d for you), or match by local name: //*[local-name()="book"]. CSS selectors do not have this problem: they match the local name in any namespace.
XPath or CSS?
CSS selectors (Selectors Level 4) are shorter for classes, ids and attributes and are what querySelectorAll() and most front-end tools use; they select elements only. XPath can go up (.., ancestor::), test text (contains(text(), "Sale")), select attributes and text nodes, and compute numbers and strings. HTML is parsed the way browsers parse it, so missing <tbody>, <html> or <body> elements are added before either runs.
Limitations
- Browsers implement XPath 1.0 only; XPath 2.0, 3.0 and 3.1 functions and syntax are reported with their XPath 1.0 equivalents where one exists.
- HTML is parsed as browsers do (with implied <tbody>, <html> and <body>), which can differ from the HTML a server-side scraper library builds.
- The document view shows the first 3,000 elements of very large documents; expressions still run on the whole document, and up to 5,000 matches are listed.
- Documents larger than 10 MB are not loaded.
Privacy
On this device: nothing is sent
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.
Frequently asked questions
What do I get without a pass?
Without a pass, XPath & CSS Selector Tester shows every match counted, with the first matches (up to 10) listed and marked in your document, and the type of any number, text or true/false result. Until you unlock it, the result can’t be downloaded or copied. A Pro, Premium or Ultimate pass, a one-time payment that never renews, unlocks the full result. The pricing page lists the passes and their prices.
Why does my XPath work in the browser console but not in my scraper?
Most often because the HTML differs: browsers add <tbody> to tables and fix broken markup, and pages change after scripts run. Test against the HTML your scraper actually receives (view the page source, or save the response), and prefer attributes and text over long positional paths.
How do I use XPath with namespaces?
Every prefix declared in the document can be used as is (//soap:Body). For the default namespace (xmlns="…") choose a prefix under Namespaces — d unless you change it — and write //d:element. You can also add mappings yourself, one prefix=URI per line, or avoid prefixes with //*[local-name()="element"].
Why does //svg find nothing in an HTML page?
Browsers put the elements of an inline <svg> (and <math>) in their own namespaces, and in an HTML page an XPath name without a prefix matches only HTML elements. So //svg and //path match nothing, in this tool as in Selenium or Playwright. Write //*[local-name()="svg"] (and /*[local-name()="path"] for the parts inside), or use a CSS selector such as svg path, which does match them.
Can I use XPath 2.0 or 3.1 functions?
No: browsers ship XPath 1.0, and that is what runs here. When you use a newer function, the tool names it and shows the XPath 1.0 way to write the same test, for example translate() instead of lower-case().
Is the absolute XPath the best one to use?
It is exact for this document, but positional paths break when the page changes. For scraping or tests, shorten it to something meaningful — an id, a stable class or attribute, or nearby text — and test it here.
Is my document uploaded?
No. Parsing and evaluation run in your browser, documents are never executed (scripts in pasted HTML do not run and images are not loaded), and the page works offline once loaded.
Do I need a pass?
To see every match, get the XPath of any node and copy or download the results, yes: a Pro pass unlocks every Pro tool. Without a pass you see a free preview of your own result: every match counted, with the first matches (up to 10) listed and marked in your document, and the type of any number, text or true/false result. Your document and expressions are never locked and never uploaded.