How to use "not" in xpath?

Guy picture Guy · Oct 11, 2009 · Viewed 140.7k times · Source

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.

Answer

James Sulak picture James Sulak · Oct 11, 2009

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

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