XPath Glossary

Short definitions for every term used on this site and in XPath discussions at work. Each entry links to the lesson or guide that goes deeper.

#

$x()
DevTools console helper that evaluates XPath and returns an array of matches. Console-only; not available in page scripts. $x("//button[@type='submit']").length Read more →

A

Absolute path
An XPath that starts at the document root with a single slash and names every step down to the target. Fragile, because any ancestor change breaks it. /html/body/div[2]/form/input[1] Read more →
Accessibility id
Appium locator strategy that uses content-desc (Android) or name (iOS). Fast and cross-platform; preferred over XPath on mobile. Read more →
Anchor
The stable starting point of a locator (a test id, landmark, heading or form) from which a short path reaches the target. //*[@role='dialog']//button[normalize-space()='Save'] Read more →
Attribute node
A name/value pair attached to an element. Selected with @name. Attributes are not children of their element and cannot be walked to from other attributes. //input/@placeholder Read more →
Axis
The direction a location step looks in, relative to the context node. XPath has 13 axes including child, descendant, parent, ancestor, following-sibling and preceding-sibling. //td/preceding-sibling::td[1] Read more →

B

Boolean conversion
How XPath turns a value into true or false when a boolean is expected: a node-set is true if non-empty, a string if non-empty, a number if non-zero and not NaN. Read more →

C

Context node
The node an expression is evaluated relative to. Inside a predicate it is the node being tested; . refers to it. //tr[td[1]='Total']
Context size and position
The number of nodes in the current context (last()) and the index of the context node within it (position()). Recalculated after each predicate. //li[position() < last()] Read more →
CSS selector
The stylesheet pattern language browsers also use for querySelector. Cannot match text or navigate upward, but pierces shadow DOM in most tools. Read more →

D

data-testid
A custom attribute added purely for tests. The most robust locator hook because nothing else depends on it. //*[@data-testid='checkout-button'] Read more →
Descendant
Any node below another in the tree: children, grandchildren and so on. Selected with // or descendant::. //form//input
Document order
The order nodes appear in the source. Node-set results are returned in document order regardless of the axis used to find them; parentheses around an expression apply indexes in this order. (//button)[1]
document.evaluate
The browser API that runs XPath. Every test tool calls it; it implements XPath 1.0 and stops at shadow roots and iframe boundaries. Read more →
DOM
Document Object Model: the tree of nodes the browser builds from HTML. XPath queries this tree, not the source text.

E

Existential comparison
When one side of =, != or < is a node-set, the comparison is true if any node satisfies it. Makes != against a node-set mean "some differ", not "none equal". //ul[not(li/@class='done')] Read more →
EXSLT
Community extension functions for XSLT and XPath 1.0. libxml2 and lxml support the regular-expressions module (re:test, re:match, re:replace). Not available in browsers. Read more →

F

Frame locator
Playwright's way of scoping locators to an iframe without switching context. The Selenium equivalent is driver.switchTo().frame(). Read more →

I

iframe
An embedded document. XPath evaluated on the parent page cannot see inside it; the test must switch into the frame first. Read more →

L

Landmark
A region with a semantic role (main, nav, dialog, form, header, footer, aside). Good anchors because they describe purpose rather than layout. //nav[@aria-label='Main']//a
local-name()
Function returning an element name without its namespace prefix. The idiom for matching inline SVG and namespaced XML. //*[local-name()='svg'] Read more →
Location path
A sequence of location steps separated by slashes. Each step has an axis, a node test and optional predicates. /child::html/descendant::form/child::input[@name="email"]
Location step
One segment of a path: axis::node-test[predicate]. //button[@type="submit"] is a single step with the abbreviated descendant axis.

N

Namespace
A URI that qualifies element names. Inline SVG and MathML elements are namespaced in HTML documents, which is why unprefixed names do not match them. Read more →
Node test
The part of a step that filters by name or type: an element name, *, text(), node(), comment() or @attr. Read more →
Node-set
The XPath 1.0 result type for element queries: an unordered set of nodes without duplicates, presented in document order. XPath 2.0 replaced it with sequences. Read more →
normalize-space()
Function that trims leading and trailing whitespace and collapses internal runs to one space. The default for matching visible labels. Does not affect non-breaking spaces. //button[normalize-space()='Save'] Read more →

P

Page object
A test-code class that owns the locators and actions for one page or component, keeping XPath strings out of test bodies. Read more →
Predicate
A filter in square brackets applied to the nodes a step selects. Evaluated per node with that node as context. //input[@type='email'][not(@disabled)] Read more →

R

Relative locator
Selenium 4 feature (above, below, toLeftOf, toRightOf, near) that finds elements by rendered position relative to another element. Geometric rather than structural. Read more →
Relative path
An XPath that starts with // or from a context node rather than the root. Survives changes elsewhere in the document. //input[@name='email'] Read more →
Reverse axis
An axis that looks backward in document order: ancestor, ancestor-or-self, preceding, preceding-sibling. Position 1 on a reverse axis is the node nearest the context node. //button/ancestor::div[1] Read more →
Robustness
How well a locator survives DOM changes. This site rates expressions stable, medium or fragile based on whether they depend on test attributes, semantics, text, or position and layout. Read more →
Role locator
A locator that queries the accessibility tree by role and accessible name, such as Playwright getByRole. Describes what users perceive; pierces shadow DOM. Read more →
Root node
The node above the document element, selected by a lone /. /html is the document element, not the root. Read more →

S

Self-healing locator
A tool feature that, when a locator fails, finds the element by a stored fingerprint and proposes a replacement. Useful for cosmetic churn; risky for destructive actions. Read more →
Shadow DOM
A separate DOM tree attached to a host element, used by web components. XPath cannot enter it from the main document in any tool. Read more →
Stale element
A Selenium reference to a node that has been removed or re-rendered since it was found. The locator is fine; re-find before acting. Read more →
Strict mode
Playwright's rule that an action's locator must resolve to exactly one element. Surfaces duplicate matches immediately. Read more →
String value
An element's string value is all of its descendant text concatenated in document order. Used when an element is passed to a string function or compared with =. //p[contains(., 'error')] Read more →

T

text()
Node test selecting the direct text-node children of the context element. Excludes text inside child elements and includes surrounding whitespace. //h1/text() Read more →
translate()
Function that maps characters in a string to other characters, deleting those with no counterpart. The XPath 1.0 idiom for case folding and stripping symbols. translate(., 'ABC', 'abc') Read more →

U

Union operator
The | operator, which combines two node-sets in document order without duplicates. XPath 1.0 has no intersect or except. //button | //a[@role='button'] Read more →

W

Wildcard
* matches any element, @* any attribute, node() any node of any type. //*[@data-testid] Read more →

X

XPath 1.0
The 1999 W3C Recommendation implemented by every browser and therefore every browser-driving test tool. 27 functions, four data types, no regex. Read more →
XPath 2.0 / 3.1
Later versions with sequences, regex, case functions, maps and arrays. Available in Saxon, BaseX, XSLT 2.0+ and XQuery engines, not in browsers. Read more →
XPath 4.0
A community-group draft extending 3.1. Not a W3C Recommendation; irrelevant to browser locators. Read more →