XPath to Playwright Locator Converter & Refactorer
Playwright Migration Suite
XPath & CSS to Playwright Resilient Refactorer
Convert XPath and CSS selectors into Playwright locators. The recommended locator always matches the same elements as your selector; more resilient alternatives are listed below it and marked Review Required.
Input Selector & Context
Try an example:
Supports absolute and relative XPaths, wildcards (*), indexes ([1]), IDs, classes, attributes, contains() / starts-with() / text(), sibling and descendant axes, and CSS combinators. Complex conditions (or, not(), ancestor::) fall back to the original selector. One selector per entry: use Bulk mode for a list.
Paste a whole migration list. XPath and CSS can be mixed. Then download the result as a .ts, .js, .py, .java, .cs or .csv file.
Paste the element (or its surrounding HTML). The selector is run against it to find the real target and read its role, label and text.
Adds a declaration to the locators, for example const saveButton = page.locator(…); in TS/JS and save_button = page.locator(…) in Python. Single selector mode only.
On (recommended): selectors on attributes such as type, rel or lang keep your XPath, because CSS also matches TYPE=”EMAIL” while XPath does not. Off: they convert to CSS and are marked Safe, which assumes your page uses the same letter case as your XPath.
Tip: press Ctrl+Enter in any box to convert.
Playwright Locators
Paste your legacy XPath or CSS selector on the left and click Refactor.