How to get the XPath of an element from Firefox inspector?

Is it possible to get the XPath of an element with the Firefox "inspect element" function (Q)?

The Chrome inspector can do this, but if I use the "Copy Unique Selector" option with Firefox's inspector, I get a selector in a different format, not XPath.

I know there are extensions, but is it possible without extensions?


It is possible, but I doubt if anyone would try it more than a couple of times

Copy the unique selector

Open Scratchpad

Switch environment to browser

Paste the following snippet

Cu.import("resource:///modules/sessionstore/XPathGenerator.jsm");
XPathGenerator.generate(content.document.querySelector("unique selector placeholder"));

Paste the unique selector then form the Execute menu select Display


I know this question is old, but this feature now exists in the Developer tools of Firefox Quantum.

After inspecting, you can right-click the tag and Copy->XPath:

enter image description here