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?
How do I get inner HTML using XPath? you can use XPath to select just content in one of two ways: Text Node Selection. This XPath, //div[@class='myclass']/text() will select the text node children of the targeted div element, content , as requested.
This document describes the interface for using XPath in JavaScript internally, in extensions, and from websites. Mozilla implements a fair amount of the DOM 3 XPath, which means that XPath expressions can be run against both HTML and XML documents.
XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.
enter image description here The XPath text() function locates elements within a text node while dot (.) locate elements inside or outside a text node.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With