How to use not contains() in XPath?

XPath queries are case sensitive. Having looked at your example (which, by the way, is awesome, nobody seems to provide examples anymore!), I can get the result you want just by changing “business”, to “Business” //production[not(contains(category,’Business’))] I have tested this by opening the XML file in Chrome, and using the Developer tools to execute that … Read more

XPath: How to select node with some attribute by index?

This is a FAQ. In XPath the [] operator has a higher precedence (binds stronger) than the // pseudo-operator. Because of this, the expression: //div[@class=”test”][2] selects all div elements whose class attribute is “test” and who (the div elements) are the second such div child of their parent. This is not what you want. Use: … Read more

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

Difference between text() and string()

Can someone explain the difference between text() and string() functions. I. text() isn’t a function but a node test. It is used to select all text-node children of the context node. So, if the context node is an element named x, then text() selects all text-node children of x. Other examples: /a/b/c/text() selects all text-node … Read more

Using upper-case and lower-case xpath functions in selenium IDE

upper-case() and lower-case() are XPath 2.0 functions. Chances are your platform supports XPath 1.0 only. Try: translate(‘some text’,’abcdefghijklmnopqrstuvwxyz’,’ABCDEFGHIJKLMNOPQRSTUVWXYZ’) which is the XPath 1.0 way to do it. Unfortunately, this requires knowledge of the alphabet the text uses. For plain English, the above probably works, but if you expect accented characters, make sure you add them … 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