48

In Firefox 50.1, Firebug is no longer available so I have to use the inspector but I cannot find copy ---> xpath option that was available in Firebug. How can I find the xpath of an element using the inspector?

Bugs
  • 4,491
  • 9
  • 32
  • 41
papakias
  • 2,925
  • 3
  • 13
  • 20

10 Answers10

44

You can use the console to check if the xpath you want return the correct element or not. $x("//div/xpath") https://developer.mozilla.org/en-US/docs/Tools/Settings

mosaad
  • 2,276
  • 5
  • 27
  • 49
39

Follow Bellow Steps:

Step 1 : Right click on page -> Select (Inspect Element)

Step 2 : Pick an element from the page

Step 3 : Right Click on highlighted html -> Copy -> Xpath

enter image description here

Nanhe Kumar
  • 15,498
  • 5
  • 79
  • 71
12

The bug related to losing ability to 'copy XPath' from firefox inspector is fixed, verified in Firefox 56 beta, and verified in Firefox 57 alpha: https://bugzilla.mozilla.org/show_bug.cgi?id=987877

Morte Descovich
  • 158
  • 1
  • 6
10

In Firefox you can use the web developer tools console for xpath validation like this:

1.Open Web Developer tools.

2.Click on Console

3.Type $x("path")

This should let you validate that your path is valid.

New Guy
  • 383
  • 2
  • 12
3

You can't, firefox's inspector does not have such feature. However it does offer css selector which can be converted to xpath with various other tools.

It should be noted however that these generated selectors (xpath or css) are not accurate or reliable and you should avoid using this feature for anything but rare edge cases.

Granitosaurus
  • 20,530
  • 5
  • 57
  • 82
  • So I suppose I should download a plugin? – papakias Jan 25 '17 at 21:46
  • There are definitely a lot of plugins/extensions that offer that, yes. However FIrebug still works with Firefox v50.1 so you are free to use that. – Granitosaurus Jan 25 '17 at 23:24
  • I don't think it still works. When I press the firebug button, the inspector opens. This happens since I updated to firefox 50.1 – papakias Jan 26 '17 at 11:58
  • 1
    why aren't xpaths reliable? – clarkep Aug 06 '17 at 18:23
  • 1
    @pjc xpaths are very reliable but automatically generated xpaths usually tend to be very stationary and based on DOM structure rather than unqiue node classes or ids. If dom structure changes you will lose your output, however if you were to select by unique classes or ids, your spider will manage to find the data even if big structural changes occur. – Granitosaurus Aug 07 '17 at 05:50
  • Gotcha. It seems like the xpaths from the chrome inspector are ok, however. – clarkep Aug 07 '17 at 06:03
2

Unfortunately this doesn't work properly. When I use the copy xpath, I got this instead of the usual one: //*[@id="gwt-uid-105"] Which is just useless :(

There aren't any extension currently which could solve this. Looks like the only way is to run an old version of FF. Can have an old 32 bit and a new 64 bit version.

Balazs
  • 21
  • 4
0

Xpath Using Firefox Console: **
Answer referenced from **Xpath Using Firefox Console in selenium webdriver

Steps:

Press F12( common for all browsers), Now firefox open developer tool like below.

  1. Naviagte to console tab

  2. On the console editor we can verify our Xpath

  3. For verifying xpath we have to use our xpath in following format : $x("xpath")
  • 1
    Thanks for your anser Pavan but I don't want to verify an xpath. I want to find the xpath of an element whose xpath is unknown to me. – papakias Jan 07 '18 at 21:38
0

This is an old question but I'm glad to say that since FF 75 it supports searching by XPath, look at documentation. Here is a link to their blog entry

  • The question asked, is how to copy the XPath of an element. Not how to search by XPath. Your links do not seem to address this. – thelogix Dec 15 '22 at 10:24
-1

I know that this doesn't answer directly to the question but it helped me a lot, use Pale Moon:

  1. Open any web page in Pale Moon browser
  2. Right click on an element of the page
  3. Select: "Inspect Element with Developer Tools" (a window shows up with element highlighted)
  4. Right click highlighted element
  5. Select: "Copy XPath"

And there you have it. You will get a "full" xpath even if the element has an id.

Josip
  • 75
  • 5
-8

I would rather you study how to create xpath on your own to select the element you need. It's very simple and very very helpful specially when creating reusable methods/functions.

Go and see the xpath tutorial at w3schools or wherever.

Focus on the relationships between elements.

Edit: Once you know how to construct a good-looking xpath, you can now test it using the browser console as mentioned by @mosaad. Still, you need to learn how to construct the xpath first. BTW, the copy xpath function wasn't available back in Jan '17. That is why I suggested he learn how to construct xpath. Even now that it is available though, I still suggest you learn because the xpath you get from those usually suck.

becixb
  • 365
  • 1
  • 9
  • 5
    The OP is not asking, what they should learn, but how to do it with existing means in Firefox. I think this answer is off-topic. – Zelphir Kaltstahl Aug 03 '17 at 15:39
  • @Zelphir I don't understand. It is basically similar to the answer of mosaad. Once you know how to construct the xpath, then you can use the browser console to test the xpath. AFAIK, getting the xpath in Firefox was not available back when the question was asked. It was only available with Firebug. The only way to get the xpath is to actually know how to construct one and test it in the console. – becixb May 11 '18 at 07:58