Switch to v2 to see which selectors break.
Add to Chrome

XPath practice website

Practice writing XPath against tables, ids that change every build, text with stray spaces, repeated links and look-alike inputs. Test each XPath live in the box below, then ship v2 and see which ones survive. Open the admin orders table

Type an XPath to test it against the practice elements below.

Valid or not? Click one to test it:

Value in a table rowGet the total for Bo Chen, wherever the row sits.

Built well

CustomerStatusTotal
Ada ParkPaid$149.00
Bo ChenShipped$56.00
Cal DiazRefunded$899.00
Dee EvansPaid$249.00

Built to break

Ada Park
Paid
$149.00
Bo Chen
Shipped
$56.00
Cal Diaz
Refunded
$899.00
Dee Evans
Paid
$249.00

Id that changes every build

Built well

Built to break

Text with stray spaces

Built well

Built to break

Save draft

Repeated Edit linksEdit Bo Chen, not "the second one".

Built well

  • Ada Park
  • Bo Chen
  • Cal Diaz

Built to break

  • Ada ParkEdit
  • Bo ChenEdit
  • Cal DiazEdit

Inputs that differ by one attribute

Built well

Built to break

Email me
Text me

Text in other scriptsHindi, Chinese and accents are fine; a non-breaking space or curly quotes are not.

Built well

Built to break

Pay now
“Gift” card

Tasks: write a locator, get a grade

1Get Bo Chen's total from the table, wherever the row sits.Axes
2Find the Edit link for Bo Chen in the built-to-break list.No names

XPath challenges

Six levels, from attributes and text to axes, build ids, tables and shadow roots. Every level is open. Each answer gets a correctness check and an A–F robustness grade with the reason.

Level 1 · Basics · challenge 1 of 4

Find the search input by an attribute it owns.

Grades come from the same engine as COR Lens, so inspecting this element with Lens shows how its own pick compares.

How to locate XPath

XPath can say exactly what you mean, or exactly where it is today

XPath can describe an element by what it is (its text, its attributes, the row it belongs to) or by where it sits. The first kind survives releases. The second kind (/html/body/div[2]/..., (//span)[3]) passes today and breaks the next time a wrapper is added or a list is re-sorted. On v2 this page does both.

Tables are where XPath earns its keep, because it can step up and across. //tr[td[normalize-space()="Bo Chen"]]/td[3] finds the total in Bo Chen’s row by anchoring on the customer cell, so sorting the table doesn’t matter. The same goes for following-sibling and ancestor: start from something stable, then move.

Ids with build numbers in them (search-48213) look stable and aren’t. starts-with(@id, "search-") keeps the part that holds. Text is the other trap: text()= fails on padded or split text, while normalize-space() compares what the reader sees.

When several elements look the same, scope by their container instead of counting: find the row that contains “Bo Chen”, then its Edit link. When two inputs differ by a single attribute, combine conditions with and.

XPath has one hard limit: it stops at shadow roots. Inside shadow DOM, use a tool’s shadow-piercing locators instead (see the shadow DOM practice page).

What a stable locator looks like

Anchor on something the element owns or belongs to (an attribute, its visible text, a stable neighbour), then move with axes. Use normalize-space() for text and starts-with() or contains() for ids with changing parts. Avoid absolute paths and indexes.

// Playwright treats a selector starting with // as XPath
const total = page.locator('//table[@data-testid="xp-table"]//tr[td[normalize-space()="Bo Chen"]]/td[3]');
await expect(total).toHaveText(/\$/);

await page.locator('//input[starts-with(@id, "search-")]').fill('headphones');
await page.locator('//div[span][normalize-space()="Save draft"]').click();
await page.locator('//li[span[normalize-space()="Bo Chen"]]//*[normalize-space()="Edit"]').first().click();
await page.locator('//label[normalize-space()="Text me"]/input[@name="notify" and @value="sms"]').check();

In a real workflow

The admin’s orders table is the real version of the first exercise: find an order’s status or total by its customer, sort the table, and check your XPath still finds the same row.

COR Lens generates locators for shadow DOM, iframes and tables, and grades each one. Click the xpath above with it and compare its pick with yours.

Add to Chrome