How to get DOM element Xpath in Firefox

Oleg Mikheev picture Oleg Mikheev · Jan 6, 2017 · Viewed 15.3k times · Source

It might be just me but I can't find any way to get DOM element's XPATH in Firefox.

That was possible in Firebug, but now it's deprecated in favor of Firefox Developer Tools, and the recommendation is not to use it any longer.

So, is there any way to get XPATH in Firefox and its Developer Tools?

Answer

Alvin Bunk picture Alvin Bunk · Jan 6, 2017

Open the developer tools in Firefox, then:

  1. Click on Console tab.
  2. Type allow paste if you are pasting anything.
  3. Type the XPath like so:

    $x("path")
    

    For example:

    $x(".//*[@id='4th']/tbody/tr[1]/td")
    

Firebug also works well, so I suggest using that instead.