为了找到<li>
包含文本“内存”但不包含文本“图形”的元素,我尝试了十几种变体:
//li[contains(text(), "memory")] and li[not contains(text(), "Graphics")]
//li[contains(text(), "memory")] and [not contains(text(), "Graphics")]
//li[contains(text(), "memory") and not contains(text(), "Graphics")]
etc etc
虽然我在 Stackoverflow 上发现了指向使用单个 boolean 运算符(如
not
)的帖子,我找不到任何解释如何将它们组合起来过滤这样的文本的东西。有什么诀窍?
最佳答案
not()是 XPath 中的函数,而不是运算符。你必须写:
//li[contains(text(), "memory") and not(contains(text(), "Graphics"))]
关于xpath - 在 XPath 中包含 boolean 表达式的正确语法;特别不是 & 和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6889832/