How to get the value of the Header tag in webdriver.

8,599 views
Skip to first unread message

pawan

unread,
Mar 6, 2012, 9:33:32 AM3/6/12
to webdriver
Hi all ,
i want to get the value of the H5 tag by using Webdriver, Can any one
please help me out in this,

div class="t1_l2_inner_clearance">
<div class="clearance_list">
<h5>Shop by Category</h5>
<ul>

i am using this code but i am getting blank value
Webdriver dd =
driver.findelement(By.classname("t1_l2_inner_clearance"));
Webdriver pp = dd.findelement(By.classname("clearance_list"));
String value = dd.findelement(By.tagname("h5")).getText();

Please help me out, thanks in advance.

Luke Inman-Semerau

unread,
Mar 6, 2012, 11:36:24 AM3/6/12
to webd...@googlegroups.com
is that element displayed on the screen. If it has the css- display:none or visibility:hidden. Then getText will not return anything, since it only returns the visible text.


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Pawan Garia

unread,
Mar 7, 2012, 1:11:32 AM3/7/12
to webd...@googlegroups.com
Yes it is displayed on Screen, Can you please help me out like how can i get the value of this Tag.
--
Regards-

PAWAN GARIA

Amit Agarwal

unread,
Mar 7, 2012, 2:15:11 AM3/7/12
to webd...@googlegroups.com
Code seems to be ok except some typo.. please recheck

Webdriver pp = dd.findelement(By.classname("clearance_list"));
String value =  dd.findelement(By.tagname("h5")).getText();      ////////////////////// pp or dd


regards,
Amit

pawan

unread,
Mar 7, 2012, 4:41:58 AM3/7/12
to webdriver
Hi Amit,
thanks for the Reply,
The code is working fine But it is not able to return the value in the
header, Because the headers don't have the attribute.
Do you have any idea like how should i do ??

Regards,
pawan

On Mar 7, 12:15 pm, Amit Agarwal <amitjhs2...@gmail.com> wrote:
> Code seems to be ok except some typo.. please recheck
>
> *Webdriver *pp = dd.findelement(By.classname("clearance_list"));
> String value =  *dd*.findelement(By.tagname("h5")).getText();
> ////////////////////// pp or dd
>
> regards,
> Amit
>
>
>
>
>
>
>
> On Wed, Mar 7, 2012 at 11:41 AM, Pawan Garia <pawanga...@gmail.com> wrote:
> > Yes it is displayed on Screen, Can you please help me out like how can i
> > get the value of this Tag.
>
> > On Tue, Mar 6, 2012 at 10:06 PM, Luke Inman-Semerau <
> > luke.seme...@gmail.com> wrote:
>
> >> is that element displayed on the screen. If it has the css- display:none
> >> or visibility:hidden. Then getText will not return anything, since it only
> >> returns the visible text.
>

aravind....@gmail.com

unread,
Mar 7, 2012, 11:45:44 AM3/7/12
to webd...@googlegroups.com, webdriver
I do not see any getAttribute("value") in your code for it to look for value attribute.

Your code is trying to get the text between the h5 tag.Which is right and you don't need to do a getAttribute here. If this is not working try By. cssSelector("h5") instead of by. Tagname. I doubt if that will make sny differnce. Also please check if any of the parent div's  display style is none or hidden.
dd.findelement(By.tagname("h5")).getText();


If you can send the URL to your page I can try helping.

Thanks,
Aravind Kannan


Sent from my phone. Please excuse the shortness and typos.

darrell

unread,
Mar 8, 2012, 10:52:12 AM3/8/12
to webdriver
This should work. Your code with data types and typos corrected.

WebElement dd =
driver.findElement(By.className("t1_l2_inner_clearance"));
WebElement pp = dd.findElement(By.className("clearance_list"));
String value =  pp.findElement(By.tagName("h5")).getText();

Darrell

Vasu

unread,
Jul 3, 2012, 2:14:28 PM7/3/12
to webd...@googlegroups.com
I am in similar situation and do not know how to handle - 
I have multiple <h5> tags and need to get text from the tag one at a time. 

<div id="one">
   <h5> One</h5>
<div id="two">
   <h5>Two</h5>

Can some one help me how to point to specific <h5> tag. 

Thanks,
Vasu.

Peter Gale

unread,
Jul 3, 2012, 2:32:54 PM7/3/12
to webd...@googlegroups.com
Try:

String value =  pp.findElement(By.XPath("//h5[2]")).getText();

This would get the text of the 2nd h5 tag, for example.


Date: Tue, 3 Jul 2012 11:14:28 -0700
From: vasav...@gmail.com
To: webd...@googlegroups.com
Subject: [webdriver] Re: How to get the value of the Header tag in webdriver.
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/DtCNQlLH8_0J.

Mark Collin

unread,
Jul 3, 2012, 5:37:09 PM7/3/12
to webd...@googlegroups.com

I would go for:

 

String value = pp.findElement(By.xpath(“//div[@id=’one’]/h5”)).getText();

 

Or

 

String value = pp.findElement(By.xpath(“//div[@id=’two’]/h5”)).getText();

 

It should be more performant to base it upon an ID since they are unique (I really need to do some tests and get some numbers to validate this, I may just be making it up)

Reply all
Reply to author
Forward
0 new messages