Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Paste HTML or XML, click any element to generate a relative XPath, absolute XPath, and CSS selector, then test the expression with live match highlighting. Everything runs in your browser, so your markup is never uploaded.
An XPath generator is a tool that builds an XPath expression pointing to a specific element inside an HTML or XML document. You paste your markup, click any element in the preview, and the generator returns a relative XPath, an absolute XPath, and a CSS selector for it. XPath is the W3C path language used by Selenium, Playwright, and web scrapers to locate elements on a page.
Under the hood it parses your markup with the browser DOMParser, walks up from the clicked element, and prefers a stable id, then a unique attribute like data-testid or name, then a class or text match, before falling back to an absolute path. The result is a locator that mirrors your element and is ready to drop into a test or scraper.
A test is only as reliable as the locators it uses. XPath gives you a precise, flexible way to target elements that CSS alone cannot reach, and a well-formed expression keeps automated checks stable as a page evolves. Here is why a good XPath matters:
Generating and testing a selector takes only a few seconds, and you do not need to install anything. Follow these steps:
As a tool, the XPath generator offers a few capabilities that make selector creation effortless. Here are the features of our generator:
An accurate XPath is useful anywhere you need to locate an element programmatically. The generator speeds up each of these workflows by building and testing the selector for you:
This generator is maintained by TestMu AI (formerly LambdaTest), the team behind a unified testing platform, so it reflects the same focus on stable locators that QA and SDET engineers depend on. Selectors built here can be run across 10,000+ real devices and 3000+ browsers on the platform. For checking the markup you are working with, the HTML Validator and CSS Validator cover related needs.
Both locate elements, but they differ in power and readability. The table below sums up how an XPath compares to a CSS selector so you can pick the right one for each case:
| Aspect | XPath | CSS selector |
|---|---|---|
| Direction | Can traverse up to parents and across siblings | Moves down the tree only |
| Text matching | Selects by visible text with functions like normalize-space | Cannot match on element text |
| Syntax | Path with predicates, e.g. //button[@id='submit'] | Compact pattern, e.g. button#submit |
| Readability | More verbose, especially for deep paths | Shorter and familiar to front-end developers |
| Typical use | Complex automation locators and scraping | Styling and simple, fast element selection |
An XPath generator is a tool that builds an XPath expression pointing to a specific element in an HTML or XML document. This generator lets you paste markup and click an element to get a relative XPath, an absolute XPath, and a CSS selector for it.
It parses your HTML with the browser DOMParser, then walks from the clicked element up its ancestors. It prefers a stable id, then a unique attribute such as data-testid or name, then a class or text match, and falls back to an absolute path when nothing else is unique.
Yes. Parsing, generation, and XPath evaluation all run in your browser using DOMParser and the native document.evaluate engine. Your HTML is never uploaded to a server, so private markup and selectors stay on your device.
An absolute XPath lists every step from the root, such as /html/body/div[2]/form[1]/button[1], and breaks easily when the page changes. A relative XPath starts with // and anchors on a stable attribute, such as //button[@id='submit'], so it is shorter and more resilient.
Yes. For every element you click, the tool outputs a CSS selector alongside the XPath, using the id when present or an nth-of-type path otherwise, so you can use whichever locator your test framework prefers.
The tool evaluates XPath 1.0, which is what browsers support natively through document.evaluate and what Selenium and Playwright use. XPath 2.0 and 3.0 functions are not evaluated because no mainstream browser ships a 2.0 engine.
Yes. Type any XPath in the test box and the tool reports how many nodes match, lists the matched markup, and highlights every match in the preview, so you can confirm a selector is unique before using it in a test.
Copying the full XPath from DevTools gives a brittle absolute path tied to the exact DOM hierarchy, so it breaks when the layout shifts. A relative XPath anchored on a stable id or attribute survives those changes and keeps automated tests reliable.
Yes, the XPath generator is completely free with no signup, subscription, or credit card required. You can paste any markup, generate selectors, and copy them with one click as often as your workflow needs.
Did you find this page helpful?
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance