XPath Cheatsheet for Text#
When you need just the content of a node, use the text()
function:
Exact Matching#
Target all <button>
nodes with a specific text content:
Get all <p>
nodes that start with placeholder text using the starts-with()
function:
Ensure that all paragraphs end with a dot by getting all <p>
nodes and combining the not()
and ends-with()
functions:
Non-Exact Matching#
Get all <h2>
header nodes that contains some text using the contains()
function:
Get all submit buttons using the normalize-space()
function that strips leading and trailing whitespace, including sequences of whitespace characters replaced with a single space. This is useful to target buttons with different text content, yet the same meaning: