Getting Title value with Webdriver

2,099 views
Skip to first unread message

gbh

unread,
Mar 23, 2011, 10:46:44 AM3/23/11
to Selenium Users
Hi,

I've got the following piece of html:

<span title="This is a really really really really long tag to test
out tooltips!!" class="value">This is a really really really really
long tag to test…</span>

where I'm trying to get the value of the title attribute. I'm using
the following code:

String tagTooltip = Global.objBrowser.findElement(By.xpath("//
div[@id='fileInfoAttrs']/p[6]/span[@title]")).getText();

but this is returning the text of the <span> element.
Any ideas on how I can do this??

Thanks,

gbh


Bill Smith

unread,
Mar 23, 2011, 11:17:50 AM3/23/11
to seleniu...@googlegroups.com, gbh
Have you tried this:

String tagTooltip = Global.objBrowser.findElement(By.xpath("//div[@id='fileInfoAttrs']/p[6]/span/@title")).getText(); 

gbh

unread,
Mar 23, 2011, 11:36:58 AM3/23/11
to Selenium Users
Thanks but it doesn't like it, getting error...

Element is no longer attached to the DOM System info: os.name:
'Windows 7', os.arch: 'x86', os.version: '6.1', java.version:
'1.6.0_23' Driver info: driver.version: remote

Bill Smith

unread,
Mar 23, 2011, 11:41:19 AM3/23/11
to seleniu...@googlegroups.com, gbh
Ok, I guess findElement really wants to retrieve an element and not an attribute.  How about this:

String tagTooltip = Global.objBrowser.findElement(By.xpath("//div[@id='fileInfoAttrs']/p[6]/span[@title]")).getAttribute("title");

If that works, then might try simplifying like this:

String tagTooltip = Global.objBrowser.findElement(By.xpath("//div[@id='fileInfoAttrs']/p[6]/span")).getAttribute("title");

Bill Smith

unread,
Mar 23, 2011, 11:43:09 AM3/23/11
to seleniu...@googlegroups.com, gbh
That was weird.  Let me try that again.  If the first thing works, you might try simplifying like this:

String tagTooltip = Global.objBrowser.findElement(By.xpath("//div[@id='fileInfoAttrs']/p[6]/span")).getAttribute("title");
 

On Wednesday, March 23, 2011 10:41:19 AM UTC-5, Bill Smith wrote:
Ok, I guess findElement really wants to retrieve an element and not an attribute.  How about this:

String tagTooltip = Global.objBrowser.findElement(By.xpath("//div[@id='fileInfoAttrs']/p[6]/span[@title]")).getAttribute("title");

If that works, then might try simplifying like this:

String tagTooltip = Global.objBrowser.findE...@id='fileInfoAttrs']/p[6]/span")).getAttribute("title");

gbh

unread,
Mar 23, 2011, 11:51:35 AM3/23/11
to Selenium Users
Thanks for that Bill, worked perfectly
(Global.objBrowser.findElement(By.xpath("//div[@id='fileInfoAttrs']/
p[6]/span[@title]")).getAttribute("title"); ).

The simplified version returned null though.
But I'm good with the first option.

Mark Collin

unread,
Mar 23, 2011, 11:52:53 AM3/23/11
to seleniu...@googlegroups.com
Use getAttribute() instead of getText()

-----Original Message-----
From: seleniu...@googlegroups.com
[mailto:seleniu...@googlegroups.com] On Behalf Of gbh
Sent: 23 March 2011 14:47
To: Selenium Users
Subject: [selenium-users] Getting Title value with Webdriver

Hi,

I've got the following piece of html:

<span title="This is a really really really really long tag to test out
tooltips!!" class="value">This is a really really really really long tag to

test.</span>

where I'm trying to get the value of the title attribute. I'm using the
following code:

String tagTooltip = Global.objBrowser.findElement(By.xpath("//
div[@id='fileInfoAttrs']/p[6]/span[@title]")).getText();

but this is returning the text of the <span> element.
Any ideas on how I can do this??

Thanks,

gbh


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


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Reply all
Reply to author
Forward
0 new messages