Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "not" in XPath?

I want to write something of the sort:

//a[not contains(@id, 'xx')] 

(meaning all the links that there 'id' attribute doesn't contain the string 'xx')

I can't find the right syntax.

like image 637
Guy Avatar asked Oct 11 '09 15:10

Guy


People also ask

How add not equal to in XPath?

Format: != If the expression is not equal to the specified value, the operator returns true. If the expression is equal to the specified value, the operator returns false. Example: price!=

Can we use and condition in XPath?

Using OR & AND This means that any one condition should be true to find the element. In the below XPath expression, it identifies the elements whose single or both conditions are true. Highlight both elements as 'First Name' element having attribute 'id' and 'Last Name' element having attribute 'name'.

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.


2 Answers

not() is a function in XPath (as opposed to an operator), so

//a[not(contains(@id, 'xx'))] 
like image 77
James Sulak Avatar answered Oct 11 '22 21:10

James Sulak


you can use not(expression) function

or

expression != true() 
like image 36
Abdelhameed Mahmoud Avatar answered Oct 11 '22 20:10

Abdelhameed Mahmoud