XPath find text in any text node

This expression //text() = ‘Alliance Consulting’ evals to a boolean. In case of this test sample: <r> <t>Alliance Consulting</t> <s> <p>Test string <f>Alliance Consulting</f> </p> </s> <z> Alliance Consulting <y> Other string </y> </z> </r> It will return true of course. Expression you need should evaluate to node-set, so use: //text()[. = ‘Alliance Consulting’] E.g. … Read more

XPath – Get node with no child of specific type

Maybe *[local-name() = ‘A’ and not(descendant::*[local-name() = ‘B’])]? Also, there should be only one root element, so for /A[…] you’re either getting all your XML back or none. Maybe //A[not(B)] or /*/A[not(B)]? I don’t really understand why /A[not(B)] doesn’t work for you. ~/xml% xmllint ab.xml <?xml version=”1.0″?> <root> <A id=”1″> <B/> </A> <A id=”2″> </A> … Read more

Locating the node by value containing whitespaces using XPath

Depending on your exact situation, there are different XPath expressions that will select the node, whose value contains some whitespace. First, let us recall that any one of these characters is “whitespace”:     &#x09; — the Tab     &#xA; — newline     &#xD; — carriage return     ‘ ‘ or &#x20; — the space If you know the exact … Read more

Getting element’s name in XPATH

Use name(). (Find docs for newer versions of the XPath language here.) Here are modified versions of your example: Works in XPath 2.0+ only: //element/*[@id=’elid’]/name() Works in XPath 1.0 and 2.0+*: name(//element/*[@id=’elid’]) *If using 2.0+, the expression //element/*[@id=’elid’] must only return one element. Otherwise you’ll get an error like A sequence of more than one … Read more

XPath : select all following siblings until another sibling

You could do it this way: ../node[not(text()) and preceding-sibling::node[@id][1][@id=’1′]] where ‘1’ is the id of the current node (generate the expression dynamically). The expression says: from the current context go to the parent select those child nodes that have no text and from all “preceding sibling nodes that have an id” the first one must … Read more

XPath test if node value is number

Test the value against NaN: <xsl:if test=”string(number(myNode)) != ‘NaN'”> <!– myNode is a number –> </xsl:if> This is a shorter version (thanks @Alejandro): <xsl:if test=”number(myNode) = myNode”> <!– myNode is a number –> </xsl:if>

What is the difference between absolute and relative xpaths? Which is preferred in Selenium automation testing?

Absolute Xpath: It uses Complete path from the Root Element to the desire element. Relative Xpath: You can simply start by referencing the element you want and go from there. Relative Xpaths are always preferred as they are not the complete paths from the root element. (//html//body). Because in future, if any webelement is added/removed, … Read more