Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using not() in XPath

Tags:

I would like how to use the "not" in XPath properly. I just can't seem to get it to work with attributes.

Say I have this expression: //*[@name = 'Bob'] It is valid, and will return all nodes that have a name attribute equaling 'Bob'.

Now if I want all nodes that have a name attribute that do not equal 'Bob', I need to use an XPath such as: //*[@name not(='Bob')] but this is invalid.

I have tried multiple combinations with not() being placed in a different order, but I can't seem to get this to work. Could someone please inform me how to use not() properly?

Also, does the order change when using elements instead of attributes? Such as: //name[text() = 'Bob']

Thanks! :)

like image 786
developer Avatar asked Aug 05 '10 19:08

developer


People also ask

What is text () in XPath?

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.

Can we ignore case in XPath?

XPath is a case-sensitive language. Keywords in XPath use lowercase characters and are not reserved. Names in XPath expressions are allowed to be the same as language keywords.

Can we use comparison operators in XPath?

XPath expressions can use comparison operators. Comparison operators compare one value to another. The resulting value is a "boolean" value. A boolean value is one that only returns either true of false.


1 Answers

According to : http://msdn.microsoft.com/en-us/library/ms256086.aspx, have you tried

//*[@name != 'Bob'] 
like image 99
mathieu Avatar answered Sep 24 '22 15:09

mathieu