Xpath and innerHTML

Jonathan. picture Jonathan. · May 9, 2010 · Viewed 9.8k times · Source

What Xpath expression can I use to find all the anchor (just 'a') elements whose actual text (the innerHTML) is Logout.

something like

//a[@innerHTML='Logout']

Would that be correct?

Answer

Fyodor Soikin picture Fyodor Soikin · May 9, 2010

No, it would be incorrect. innerHTML is a property, part of the object model, while XPath operates on tags and attributes. Unless your a tag actually has an attribute named innerHTML, this wouldn't work.

If you want to compare the value of the tag itself, you can use the . (dot) to refer to the tag:

a[.='Logout']

However, I must add, just in case you're using jQuery: I'm not sure if it will work with jQuery. jQuery does not support XPath fully, only basic stuff.