Skip to content

XPath to CSS Selector Converter

Turn XPath into CSS selectors — and say plainly when CSS cannot express one.

Used for moving Selenium or Scrapy selectors to Playwright, Cypress or querySelectorAll.

CSS selectors

Quick Tool Overview

The XPath to CSS Selector Converter translates expressions line by line — attributes, contains, starts-with, positions and last() — and says plainly when CSS cannot express one.

What it does
Converts XPath to CSS selectors
You give it
XPath expressions, one per line
You get back
CSS selectors, or the reason there is none
Best for
Moving tests to Playwright or Cypress
Converters Free, unlimited use No sign-up Runs in your browser

About the XPath to CSS Selector Converter

Old test suites are full of XPath. Newer tools — Playwright, Cypress, Testing Library, plain querySelectorAll — prefer CSS, which is shorter, faster in most engines, and far easier to read in a code review. Translating dozens of selectors by hand is dull and error-prone.

Paste a list of expressions, one per line, and get CSS. Attribute matches, contains(@class, …), starts-with(@href, …), position filters, last(), descendant and child steps, wildcards and namespace prefixes are all handled. Where CSS genuinely cannot express something — a parent axis, matching on text() — the line says so instead of producing a selector that quietly matches the wrong element, which is the worst thing a converter can do to a test suite.

Key features of the XPath to CSS Selector Converter

The common predicates

Attribute equality, contains(), starts-with(), [n] and last().

Correct position translation

[3] becomes :nth-of-type(3), not :nth-child(3).

Honest failures

A parent axis or text() match reports why, rather than guessing.

Whole files at once

Paste a page-object file and convert every line together.

Side-by-side table

Each XPath next to its CSS, ready to copy one at a time.

How to use the XPath to CSS Selector Converter

  1. 1

    Paste your XPath expressions

    One per line — a whole page-object file is fine.

  2. 2

    Read the converted selectors

    Each line converts in place, with a table underneath.

  3. 3

    Check the ones that failed

    The reason is written where the selector would be.

  4. 4

    Copy them into your tests

    Ready for Playwright, Cypress or querySelectorAll.

Frequently asked questions

CSS has no parent or ancestor axis and cannot match text content. //div/parent::section and //a[text()="Next"] have no CSS equivalent — Playwright’s :has() and text engines cover some of those cases.

Reviews of the XPath to CSS Selector Converter

What people who use the XPath to CSS Selector Converter think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the XPath to CSS Selector Converter. It takes half a minute and no account.

Write the first review

More converters