How to use the XPath Tester (Selenium)
- 1. Paste HTMLCopy outerHTML or page source from DevTools and paste it.
- 2. Type a locatorChoose XPath or CSS and write your expression.
- 3. Read the matchesSee the count, the matched elements and Selenium code to copy.
How the tester works
Your HTML is parsed with the browser's own DOMParser, which builds a document without running any scripts in it. XPath expressions are evaluated with the built-in document.evaluate, and CSS selectors with querySelectorAll, the same engines browsers use for Selenium's locators.
Example: the default login form has two inputs. The XPath //input[@type='password'] returns 1 match, so it is unique and safe to use. //input returns 2 matches, which would make findElement pick the first one silently. Functions that return a value, such as count(//input), show the value instead of elements.
Writing locators that do not break
- Prefer relative XPath starting with //. Absolute paths like /html/body/div[2]/form break with any layout change.
- Use stable attributes: id, name, data-testid, aria-label.
- Match text carefully:
normalize-space()ignores extra spaces thattext()does not. - Use axes like following-sibling to find an input next to its label.
- Check uniqueness on the full page, not just a snippet.
Pasted source is a snapshot. Content added by JavaScript after load only appears if you copy the HTML from the Elements panel after the page has rendered. In Chrome DevTools you can also run $x("//xpath") in the console. Generate locators automatically with the Selenium locator generator, and keep the locators cheat sheet open while you write.
Frequently asked questions
Does it support XPath 2.0 functions?
No. Browsers, and Selenium in the browser, support XPath 1.0, so functions like matches() or lower-case() are not available.
Is my HTML uploaded?
No. It is parsed and searched entirely in your browser.
Is the XPath Tester (Selenium) free?
Yes, the XPath Tester (Selenium) is free. The first time you test your first locator, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.