Discussion:
[selenium-users] Capturing the text between h1 tag
Ramesh D
2015-08-26 19:57:16 UTC
Permalink
I am very new to Selenium and Java. Still trying to learn.

I have come across an issue where I need to extract the text between h1
tags. Tried a lot and nothing worked.


<div class="abcd">
<h1 class="condensed">Header Titles </h1>
</div>

Can someone guide me to extract "Header Titles" from this script...Thanks
in advance
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a3cf9093-d0b4-46c5-894e-315a7b6171ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sridhar U
2015-08-27 05:11:21 UTC
Permalink
driver.findelement(By.xpath(''//h1[@class='condensed']").text()

-Sri...
Post by Ramesh D
I am very new to Selenium and Java. Still trying to learn.
I have come across an issue where I need to extract the text between h1
tags. Tried a lot and nothing worked.
<div class="abcd">
<h1 class="condensed">Header Titles </h1>
</div>
Can someone guide me to extract "Header Titles" from this script...Thanks
in advance
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d3bb06e2-fb76-413a-af55-9dca9fb1d634%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Anand Somani
2015-08-27 05:41:57 UTC
Permalink
driver.findelement(By.xpath(''
Post by Sridhar U
-Sri...
Post by Ramesh D
I am very new to Selenium and Java. Still trying to learn.
I have come across an issue where I need to extract the text between h1
tags. Tried a lot and nothing worked.
<div class="abcd">
<h1 class="condensed">Header Titles </h1>
</div>
Can someone guide me to extract "Header Titles" from this script...Thanks
in advance
--
You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/selenium-users/d3bb06e2-fb76-413a-af55-9dca9fb1d634%40googlegroups.com
<https://groups.google.com/d/msgid/selenium-users/d3bb06e2-fb76-413a-af55-9dca9fb1d634%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
~ Anand Somani
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAEVRH1E%3DtKdnaWhU7ODqXpHO96%2Be71yE2_DkuUnb9np0strV2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Ramesh D
2015-08-27 15:03:47 UTC
Permalink
Thanks Sridhar and Arvind. Worked like a charm
Post by Sridhar U
driver.findelement(By.xpath(''
Post by Sridhar U
-Sri...
Post by Ramesh D
I am very new to Selenium and Java. Still trying to learn.
I have come across an issue where I need to extract the text between h1
tags. Tried a lot and nothing worked.
<div class="abcd">
<h1 class="condensed">Header Titles </h1>
</div>
Can someone guide me to extract "Header Titles" from this
script...Thanks in advance
--
You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/selenium-users/d3bb06e2-fb76-413a-af55-9dca9fb1d634%40googlegroups.com
<https://groups.google.com/d/msgid/selenium-users/d3bb06e2-fb76-413a-af55-9dca9fb1d634%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
~ Anand Somani
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f77bd2e6-2e56-4b70-8969-3a50ea9b31a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
pS
2015-08-27 17:33:05 UTC
Permalink
Hi ramesh, the solutions provided above is no doublt correct...
As you are still learning and infact we all are on this group. I would suggest you to use xpath as last resort. Use direct attributes like id, name etc if possible otherwise use css.

For your question use driver.findelement(By.css(".condensed").getText();

Try using css instead of xpath. You will lean eventually why.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f9d2c25c-776d-4374-842c-b5818cc3f490%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...