8

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?

2

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

| improve this answer | |
1

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

| improve this answer | |
0

You can use Firebug extension on Firefox to get xpath expression. Chrome Inspector or firebug do not generate more accurate xpath which are based on attributes like Class, ID or related attributes, example below

//div[@class="address"]
//span[@id='phone']

So in that cause you can use some kind of xpath expression generator tools like http://webdata-scraping.com/xpath-generator/

Which has point and click user interface to generate different types of Xpaths.

| improve this answer | |
  • Thanks for that link to XPath Generator. It's frustrating that the descendant of FireBug doesn't support generation of XPaths in Firefox, so that tool is a helpful replacement for that functionality. – NewSites Aug 16 '17 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.