问题
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.
回答1:
not() is a function in xpath (as opposed to an operator), so
//a[not(contains(@id, 'xx'))]
回答2:
you can use not(expression) function
or
expression != true()
回答3:
None of these answers worked for me for python. I solved by this
a[not(@id='XX')]
Also you can use or condition in your xpath by | operator. Such as
a[not(@id='XX')]|a[not(@class='YY')]
Sometimes we want element which has no class. So you can do like
a[not(@class)]
回答4:
Use boolean function like below:
//a[(contains(@id, 'xx'))=false]
来源:https://stackoverflow.com/questions/1550981/how-to-use-not-in-xpath