How to retrieve link innertext using xpath?

605 views
Skip to first unread message

sbtang

unread,
Dec 7, 2010, 3:28:05 PM12/7/10
to Selenium Users
Hi folks, i hope this is an easy question.

So i am trying to use selenium get_attribute to get the innertext of a
link? For example,if my link is defined as

<a href=www.yahoo.com>YAHOO</a> how would i use get_attribute to get
YAHOO returned?

So i have tried the following

selenium.getAttribute("//a[contains(@href, 'list')]@href")
selenium.getAttribute("//a[contains(@href, 'list')]@text")
selenium.getAttribute("//a[contains(@href, 'list')]@innertext")

and they all fail.. is it easy to get what i am looking for? It makes
sense to be?

Thanks,
Steve

Pavandeep Puddupakkam

unread,
Dec 7, 2010, 5:18:36 PM12/7/10
to Selenium Users
Try this selenium.getText("//a[@href]")

For more information on using xpath in selenium visit -
http://www.seleniumwiki.com/?s=xpath

BillR

unread,
Dec 7, 2010, 6:35:03 PM12/7/10
to Selenium Users
To debug, you might try printing

selenium_.getXpathCount(("//a[contains(@href, 'list')]").intValue();

mam_p

unread,
Dec 7, 2010, 8:55:41 PM12/7/10
to Selenium Users

I'm completely confused where that "list" is coming from. It's not in
the page's code snippet you sent, so why is it in your Selenium
snippet? Something more like this....

selenium.getText("//a[contains(@href,'yahoo')]")

seems like what you need to me. Is the "list" you've used an attempt
to parameterize what you send in to Selenium?

--mam-p

On Dec 7, 12:28 pm, sbtang <sbt...@gmail.com> wrote:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages