DevTools Tips

Evaluate XPath to find elements in the page

DevTools supports 2 ways to evaluate XPath expressions to help you locate elements in the page. All browsers support those 2 ways:

  • From the Elements (or Inspector) panel:
    • Click anywhere in the panel to make sure it has focus
    • Press ctrl+F (or cmd+F on Mac) to focus the search field
    • Enter your XPath expression and press enter to find the elements that match

The Inspector panel in Firefox showing the search field with an XPath expression.

Note that you can also copy the XPath expression from any element in DevTools.

  • From the Console panel:
    • You can use the built-in $x() helper function like this:
$x('//div/div/label');

The Console panel in Safari showing an array of elements, as the result of executing the above function.