how to search dom elements using xpath or css selectors in chrome developer tools ?

4,710 views
Skip to first unread message

Bo

unread,
Apr 14, 2011, 11:08:19 AM4/14/11
to Google Chrome Developer Tools
The doc http://code.google.com/chrome/devtools/docs/elements.html says
it supports xpath or css selectors but when I tried, did not seem to
work for me. Any one knows how to use it? Thanks!

PhistucK

unread,
Apr 14, 2011, 12:30:40 PM4/14/11
to google-chrome-...@googlegroups.com, Bo
Going to http://code.google.com/chrome/devtools/docs/elements.html and searching for -
a[class = 'menuItem']
Or
*[class = 'menuItem']
Works and indeed yields results.

On the other hand, searching for -
//a[class = 'menuItem']
Or
div/a[class = 'menuItem']
Or
*[class != 'menuItem']
Yields no results.

So it seems like the XPath support is very very limited to very simple expressions.
This is disappointing.

PhistucK

Alexander Pavlov

unread,
Apr 14, 2011, 12:45:47 PM4/14/11
to google-chrome-...@googlegroups.com, Bo
On Thu, Apr 14, 2011 at 8:30 PM, PhistucK <phis...@gmail.com> wrote:
Going to http://code.google.com/chrome/devtools/docs/elements.html and searching for -
a[class = 'menuItem']
Or
*[class = 'menuItem']
Works and indeed yields results.

On the other hand, searching for -
//a[class = 'menuItem']
Or
div/a[class = 'menuItem']
Or
*[class != 'menuItem']
Yields no results.

So it seems like the XPath support is very very limited to very simple expressions.
This is disappointing.

In XPath, you need to use @ in front of attribute names. Thus, //a[@class = 'menuItem'] should work for you.
If you look at the code, a real XPath query is performed against the DOM.

--
-alexander

PhistucK

unread,
Apr 14, 2011, 12:55:25 PM4/14/11
to google-chrome-...@googlegroups.com, Alexander Pavlov, Bo
Right!
Oh, this is so sad, I am already losing my XPath skills. :(

Though, why is -
*[@class != 'menuCategory default']
Or 
*[@class = 'menuItem']
Not working, whereas -
*[class = 'menuItem']
Is working?
"class" is an attribute and that is its exact value.

PhistucK

Bo

unread,
Apr 15, 2011, 10:03:17 AM4/15/11
to Google Chrome Developer Tools
Ok. It seems to me now that the dev tools do work with xpath and css
selectors search in the sense of being able to find matches. But it
can NOT highlight search results as it does for plain tex search,
that's why it made me think its not working in the first place. Can
anyone confirm that? Thanks!

On Apr 14, 12:55 pm, PhistucK <phist...@gmail.com> wrote:
> Right!
> Oh, this is so sad, I am already losing my XPath skills. :(
>
> Though, why is -
> *[@class != 'menuCategory default']
> Or
> *[@class = 'menuItem']
> Not working, whereas -
> *[class = 'menuItem']
> Is working?
> "class" is an attribute and that is its exact value.
>
> ☆*PhistucK*
>
> On Thu, Apr 14, 2011 at 19:45, Alexander Pavlov <apav...@chromium.org>wrote:
>
>
>
>
>
>
>
> > On Thu, Apr 14, 2011 at 8:30 PM, PhistucK <phist...@gmail.com> wrote:
>
> >> Going tohttp://code.google.com/chrome/devtools/docs/elements.htmland

PhistucK

unread,
Apr 15, 2011, 10:12:58 AM4/15/11
to google-chrome-...@googlegroups.com, Bo
It does highlight them for me (when pressing Enter).
Though it does not move the view to the current result.
PhistucK
Reply all
Reply to author
Forward
0 new messages