Chrome
This can be achieved by three different approaches (see my blog article here for more details):
- Search in
Elements
panel like below - Execute
$x()
and$$()
inConsole
panel, as shown in Lawrence’s answer - Third party extensions (not really necessary in most of the cases, could be an overkill)
Here is how you search XPath in Elements
panel:
- Press F12 to open Chrome Developer Tool
- In “Elements” panel, press Ctrl+F
- In the search box, type in XPath or CSS Selector, if elements are found, they will be highlighted in yellow.
Firefox (since version 75)
Since FF 75 it’s possible to use raw xpath query without evaluation xpath expressions, see documentation for more info.
Firefox (prior version 75)
- Either select “Web Console” from the Web Developer submenu in the
Firefox Menu (or Tools menu if you display the menu bar or are on Mac OS X)
or press the Ctrl+Shift+K (Command+Option+K on OS X) keyboard shortcut. -
In the command line at the bottom use the following:
-
$()
: Returns the first element that matches. Equivalent todocument.querySelector()
or calls the$
function in the page, if it exists. -
$$()
: Returns an array of DOM nodes that match. This is like fordocument.querySelectorAll()
, but returns an array instead of aNodeList
. -
$x()
: Evaluates an XPath expression and returns an array of matching nodes.
-