How to search DOM elements using XPath or CSS selectors in Chrome Developer Tools?

DomGoogle ChromeGoogle Chrome-Devtools

Dom Problem Overview


The doc http://code.google.com/chrome/devtools/docs/elements.html says it supports XPath or CSS selectors, but when I tried, didn't seem to work for me.

Any one knows how to use it?

Dom Solutions


Solution 1 - Dom

You can use $x in the Chrome javascript console. No extensions needed.

ex: $x("//img")

Solution 2 - Dom

Just typing xpath expression in the search box should work. It works for me in tip-of-tree build.

The feature seems to be broken in Chrome 11 though, I've filed a bug on this: http://crbug.com/79716

Solution 3 - Dom

For xpath searches use $x('xpathSelector'). For a css selector use $('cssSelector').

However, this last selector returns only the first matching element. If you want to see all matching elements go for $$('cssSelector')

Solution 4 - Dom

If you click on any element in the elements pane then type command-F, it will open a search bar that lets you search for elements using xpath selectors.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBoboView Question on Stackoverflow
Solution 1 - DomMatt PolitoView Answer on Stackoverflow
Solution 2 - DomYury SemikhatskyView Answer on Stackoverflow
Solution 3 - DomchamView Answer on Stackoverflow
Solution 4 - DomspacetherView Answer on Stackoverflow