CSS & XPath Selector Tester

Paste HTML, type a CSS selector or XPath expression, and see every match instantly — with the exact scraper code (Python, Scrapy, Cheerio, Playwright) to copy into your project. No signup, no ads, 100% in your browser.

Type a selector to see matches.

🔒 Private by design: this tool runs entirely in your browser. Your data is never uploaded to any server.

📖 Want the full background? Read the guide: learn when and how to use this tool.

CSS selector or XPath — which should you use for scraping?

Both reach the same elements; the difference is ergonomics. CSS selectors are shorter and cover 95% of scraping needs (.price, div#main a[href^="/item"]). XPath wins when you need to select by text content (//a[contains(text(),"Next")]), walk up the tree (/../..), or grab text nodes and attributes directly (//span/@data-id). This tester supports both, so you can compare them on the same HTML.

Quick reference

GoalCSS selectorXPath
Element by class.price//*[@class="price"]
Element by id#main//*[@id="main"]
Direct childul > li//ul/li
Attribute valuea[href] (element only)//a/@href
Contains text— not possible//a[contains(text(),"Next")]
Nth matchli:nth-child(3)(//li)[3]
Parent element— not possible//span[@class="price"]/..

Why use this tester?

Frequently asked questions

How do I test a CSS selector against my own HTML?

Paste your HTML in the left box and type a selector like div.product > h2 a in the selector field. Matches appear instantly with a count, and you can view the matched elements as text, HTML, or a specific attribute value.

Does this tool support XPath?

Yes. Switch the mode to XPath (or leave it on Auto — expressions starting with /, ./ or ( are detected as XPath automatically) and write expressions like //div[@class="price"]/text(). Evaluation uses the browser’s native XPath engine (XPath 1.0), the same one Scrapy and lxml users target most often.

Can I get scraper code for my selector?

Yes — once your selector matches, the tool generates ready-to-run snippets for Python (BeautifulSoup and lxml/parsel), Scrapy, JavaScript (Cheerio) and Playwright, with your selector and HTML-handling boilerplate filled in.

Is my HTML uploaded to a server?

No. Parsing and matching run entirely in your browser using its built-in HTML parser. Nothing you paste leaves your device — you can even load the page and then go offline.

Why does my selector work here but not in my scraper?

The most common reason: your scraper fetches raw HTML, but the content you see in DevTools was added by JavaScript after page load. Test against the HTML your scraper actually receives (e.g. from response.text), not the DevTools DOM. Also note that browser parsers auto-insert elements like <tbody>, which affects XPath paths.