XPath Tester & Generator
Click any element to get a reliable XPath and CSS selector, or use the XPath tester to see every match of an expression highlighted, in an HTML page or an XML document.
Safe by design
Scripts in pages you load or paste never run, and nothing is stored.
Fast, no sign-up
No account and no daily limit for normal use.
Built for developers
Made for scraping, testing, SEO checks and front-end work.
Find and test XPath for web scraping and testing
Click an element in the preview and you get a short XPath based on its id or attributes, the full path from the root, and a CSS selector. Type your own expression and every match is outlined, counted and listed with its tag and text, so you can see at once if it's too broad or too narrow.
Your own browser parses the HTML, so results match what you see in developer tools.
How to use it
- 1Paste HTML into the Source tab, open a file, or enter an address and press Load.
- 2Click any element in the preview or the Tree to get its XPath and CSS selector.
- 3Type your own XPath: the match count updates as you type, and Enter steps through the matches.
- 4Copy the selector you need, or switch to XML / Odoo mode for XML documents.
XPath or CSS selector
CSS selectors are shorter, easier to read and what most front-end code already uses. XPath can do a few things CSS can't: match on text, as in //button[normalize-space()='Add to basket'], climb back up the tree with .. or ancestor::, and pick an element by its neighbour with following-sibling::.
Modern CSS has :has() for some parent cases, but it still can't match text. A sensible habit is CSS by default and XPath when you need the text or the parent. Every element you click gets both, so you can compare them side by side.
How the generated XPath is chosen
- An id, if no other element on the page has it.
- Otherwise a stable attribute: data-testid, data-test, data-qa or data-cy first, then name, aria-label, title, alt, placeholder, type, href and a few more.
- For a short element with no children, its exact text, as long as that's unique.
- Failing that, a path from the nearest ancestor that can be pinned down, such as //div[@id='cart']/ul/li[2].
- The full path from /html is offered too. It breaks as soon as the layout shifts, so keep it as a last resort.
Expressions worth knowing
- //a[contains(@href, '.pdf')]: every link to a PDF.
- //h2[normalize-space()='Pricing']/following-sibling::p[1]: the first paragraph after a heading.
- //tr[td[1]='Total']/td[2]: the second cell in the row whose first cell says Total.
- (//li)[last()]: the last list item on the page. Without the brackets, //li[last()] gives the last item of every list.
- count(//img[not(@alt)]): how many images have no alt attribute. Expressions that return a number, text or true/false show that value instead of a list of matches.
Related tools
What Our Users Say
Real feedback from people using WeblixTools, checked by our team before it appears.
Frequently Asked Questions
Which XPath version does the tester support?
XPath 1.0, the version built into every browser and used by Selenium, Playwright, Puppeteer, Scrapy and lxml. Functions such as contains(), starts-with(), text() and normalize-space() all work.
Why does my XPath work here but not in my scraper?
Browsers fix up HTML while parsing it, for example by adding tbody inside tables. If your scraper reads the raw HTML without a browser, remove tbody from the path or use a shorter, attribute-based XPath such as //table[@id='prices']//tr.
Is my HTML uploaded?
No. Pasted HTML is parsed and tested in your browser tab only. When you use Load from URL, our server fetches that page for you and sends its HTML back without storing it.
Does the page's JavaScript run?
No. Scripts are disabled in the preview for your safety, so content a page adds with JavaScript won't appear. Paste the HTML from your browser's Elements panel if you need that content.