Getting the text from the inspect / find box

7,158 views
Skip to first unread message

Tony Chamberlain

unread,
Jun 17, 2016, 11:35:47 AM6/17/16
to Google Chrome Developer Tools
Hi

I remember some way when you are inspecting with Chrome and you find a web element in the search box you can have it display the text.
I mean you can see the HTML but I want to see what the actual text it would return (for instance if you did an element.getText() in selenimu/Java).
I remember doing that a few years ago, but maybe with Firebug not Chrome?  Is there a way?

for instance in this example, //*[contains(text(),'Text line ')] works, but //*[contains(text(),'Second')] does not though it seems to me it should.


<div class="text-medium">
Text line 1
<span class="icon-updated"></span>
Second text
<span class="icon-updated"></span>
My third line
<span class="icon-updated"></span>
The fourth line
</div>

I can get the di'v xpath which is  //*[@id='ext-gen1157']/div (can change with each build but I can always find the new id).
So I would like to be able to find this element in the search box in the inspect window and have it show me all the text it thinks has it.
It is this div that //*[contains(text(),'Text line ')] finds.

I also would like to figure out why //*[contains(text(),'Second')]  (nor trying to find the third and fourth line) finds anything.

PhistucK

unread,
Jun 17, 2016, 11:39:52 AM6/17/16
to Google Chrome Developer Tools
This is actually an XPath question rather than a Developer Tools question.
I believe text() refers to a text node within the element. If you do not specify its position, it might default to the first, not exactly sure.
However, changing this to -
//*[text()[contains(., 'Second')]] does find the element.

Regarding showing the text, this works -
//*/text()[contains(., 'Second')]


PhistucK

--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/07bd4b39-7e6c-4f7c-b592-8af490667c56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tony Chamberlain

unread,
Jun 17, 2016, 1:57:11 PM6/17/16
to Google Chrome Developer Tools
How can I see whether there is a @class with icon-updated after it.  Everything seems to just find the div.  Each could have its own updated icon or not.

PhistucK

unread,
Jun 17, 2016, 3:36:35 PM6/17/16
to Google Chrome Developer Tools
Please, find an XPath tutorial. This is out of scope for this group.
XPath is a very powerful selector language and you can pretty much find everything with it.


PhistucK

--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.

Tony Chamberlain

unread,
Jun 20, 2016, 9:27:14 AM6/20/16
to google-chrome-...@googlegroups.com
Actually the original intent of this message was to ask how in the chrome inspect box I could get the text of a web element (what you would get if in Java you did a findElement(By.xpath(...)).getText().  I remember doing it a long time ago but can't remember how, but it would display the text in a little popup window.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-chrome-developer-tools/rFEK0Ds_YfQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/CABc02_%2BWF9Ns45CambTu0uURgrDfLkUwLRP76VidQ6k8qQKmoQ%40mail.gmail.com.

PhistucK

unread,
Jun 20, 2016, 11:19:52 AM6/20/16
to Google Chrome Developer Tools
I do not remember any popups with the text of the element. You can get the text by selecting the element and typing in the console $0.textContent. $0 is the currently selected element in the Elements panel.


PhistucK

Reply all
Reply to author
Forward
0 new messages