How can I verify my XPath?
I am using Chrome Developers tool to inspect the elements and form my XPath. I verify it using the Chrome plugin XPath Checker, however it does not always give me the result. What is a better way to verify my XPath.
I have also tried using Firebug to inspect the bug and also using the FirePath to verify. But does Firepath also verify the XPath.
My last option would be to use the Selenium WebDriver to confirm my XPath.
Best Answer
Chrome
This can be achieved by three different approaches (see my blog article here for more details):
Elements
panel like below$x()
and$$()
inConsole
panel, as shown in Lawrence's answerHere is how you search XPath in
Elements
panel: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)
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.Firefox (prior version 49)
FirePath
panel