3

I used to use FirePath and FireBug for XPath support in Firefox a long time ago, but those tools haven't worked with Firefox for some time. I was disappointed but found that I could still use the find feature in the inspector developer tool to look up elements. Today however (with Quantum 65.0.1, x64), I found it does not work anymore. See the //div search in the find box, highlighted in dark red:

Firefox doesn't find divs by XPath

I checked the developer tools settings and found nothing related to XPath search. I can still right-click an element and Copy its XPath. Is there anything I can do to search by XPath in Firefox these days?

nikodaemus
  • 2,713
  • 3
  • 22
  • 23

2 Answers2

4

Searching elements by XPath within the DevTools Inspector is only available since Firefox 75. See bug 963933 for more information.

Note that you can also search elemnets by XPath using the command $x() in the console, or use the add-on Try XPath.

Sebastian Zartner
  • 771
  • 1
  • 5
  • 12
  • Good reminder about `$x()`. Not as convenient as just typing `Ctrl + F`, but it works – nikodaemus Feb 19 '19 at 19:23
  • 1
    The ticket was finally fixed in 2020q1. The search field is at the top of Firefox's Developer Tools, not in the middle like Chrome. The XPATH locator log is not quite as powerful as Chrome, for instance subscripted arrays don't seem to work. – MarkHu Apr 27 '20 at 11:24
  • @MarkHu Yes, and it was me that implemented it because I was also missing this feature for quite some time. I am wondering what you mean by "subscripted arrays", though. If you can provide an example and [file a bug](https://bugzilla.mozilla.org/enter_bug.cgi?bug_type=enhancement&component=Inspector&product=DevTools) for it, I might have a look and see if that can be added. For what it's worth, I've filed the follow-up [bug 1620049](https://bugzilla.mozilla.org/show_bug.cgi?id=1620049) to add an autocompletion to the feature. – Sebastian Zartner Apr 29 '20 at 21:28
  • Instead of subscripted arrays, maybe I should have said, "indexed elements." Example: `(//div)[4]` found the 4th `div` element in XPATH and Chrome's DevTools, but not Firefox [yet!] for some reason. – MarkHu May 06 '20 at 03:48
  • 1
    The reason for that is that the [string entered into the search field currently needs to start with a slash](https://searchfox.org/mozilla-central/rev/dc4560dcaafd79375b9411fdbbaaebb0a59a93ac/devtools/server/actors/utils/walker-search.js#213) in order to trigger the XPath search. I have filed [bug 1635970](https://bugzil.la/1635970) to lift that restriction. Thank you for the hint, @MarkHu! – Sebastian Zartner May 06 '20 at 22:49
  • I have also updated my answer now to note that the feature got implemented in the meantime. – Sebastian Zartner May 06 '20 at 22:55
  • @MarkHu For your information, I have created a patch for the aforementioned bug report which landed two days ago. With that change, the full feature set of XPath expressions is supported in the search field. – Sebastian Zartner Jun 27 '20 at 21:40
0

In newer version of Firefox it's direct. Tested on v104.0.2

For instance, open up example.com

Example.com

Open the inspector and type-in //html/p in the top bar and press Enter. You get the first <p> immediately selected:

html p

Press Enter again and it'll loop over the search results. So it'll select the next <p> and so on.

Xavi Montero
  • 523
  • 6
  • 19