Finding XPath elements by content

0 views
Skip to first unread message

Eric C

unread,
Oct 29, 2008, 10:30:59 AM10/29/08
to webdriver
In HTML:
<a href="#">Text</a>
<a href="#">More Text</a>

I can't seem to get the XPath syntax right for finding the "Text"
WebElement only.

"//a[contains(.,'Text')]" gets both of them.
"//a['Text']" gets both of them also.

Is there some exact match syntax I could use to only get the 1st one?

Eric C

unread,
Oct 29, 2008, 10:51:14 AM10/29/08
to webdriver
I think I figured it out -

//a[.='Text']

Simon Stewart

unread,
Oct 29, 2008, 3:00:13 PM10/29/08
to webd...@googlegroups.com
Hi Eric,

I would recommend against using xpaths if you can help it. The engine
in IE is one of the fastest out there, but it doesn't go as fast as a
native XPath implementation would, and the different implementations
on different browsers could cause headaches. I do understand that
sometimes xpath is the only way to get to a node, so it's something
that might be used, but in this case, you could do the same thing
using: By.linkText("Text")

Regards,

Simon

Reply all
Reply to author
Forward
0 new messages