Is there a way of writing an XPath expression to select the content of the element.
e.g.
<Element>xxx</Element>
Assuming I can write XPath (/Element) to get Element
how do I tweak the XPath to get xxxx returned rather than the Element wrapper?
EDIT/ANSWER
To do this in dom4j world use the Element.valueOf(String xpathExpression)
rather than the .selectXXX() methods.
Do note that /html/text() doesn't select all text nodes in the document -- only the text nodes that are children (not descendents) of the top, html element. You probably want /html//text() . Some knowledge and understanding of XPath is typically required in order to construct XPath expressions.
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.
We can find an element using the xpath locator with Selenium webdriver. To identify the element with xpath, the expression should be //tagname[@attribute='value']. To identify the element with xpath, the expression should be //tagname[@class='value']. There can be two types of xpath – relative and absolute.
In XPath, path expression is used to select nodes or node-sets in an XML document. The node is selected by following a path or steps.
Use the value-of
element:
<xsl:value-of select="/Some/Path/To/Element"/>
If you can only specify an XPath then use the text
function like this:
/Some/Path/To/Element/text()
A bit too late but...
data(Element)
...should also be fine.
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