How to use “not” in xpath?

前端 未结 4 791
旧时难觅i
旧时难觅i 2020-11-29 22:44

I want to write something of the sort:

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

(meaning all the links that there \'id\' attribute doesn\'t contain t

相关标签:
4条回答
  • 2020-11-29 23:06

    you can use not(expression) function

    or

    expression != true()
    
    0 讨论(0)
  • 2020-11-29 23:13

    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)]
    
    0 讨论(0)
  • 2020-11-29 23:22

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

    //a[not(contains(@id, 'xx'))]
    
    0 讨论(0)
  • 2020-11-29 23:23

    Use boolean function like below:

    //a[(contains(@id, 'xx'))=false]
    
    0 讨论(0)
提交回复
热议问题