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.
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
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
panelHere is the ChroPath extension for Chrome which have many advanced features compare to FirePath- Please follow the steps below : 1) Open devtools panel. 2) Right-click anywhere on the webpage. 3) Click Inspect. 4) In the right side of Elements tab, click on ChroPath tab. Here you will get the XPath/CSS and you can also edit and evaluate it.
Download addon
Another option to check your xpath is to use selenium IDE.
By using chrome or Opera
without any plugins, without writing any single XPath syntax character
;)
You can open a Console in Chrome and Firefox, and check the XPath by typing
$x("your_xpath_here")
. This will return an array of matched values. If it is empty, you know there is no match on the page.For example:
Update (March 2016):
A new screenshot from Chromium v48:
*
I verify XPath and Css selectors using Natu WebSync extension for Chrome.
It can:
It can be very useful for those who need to write and verify complex selectors.
https://chrome.google.com/webstore/detail/natu-websync/aohpgnblncapofbobbilnlfliihianac