Correct syntax for including boolean expressions in XPath; specifically not & and
In order to find <li>
elements that contain the text "memory" but not the text "Graphics", I have tried a dozen variation of:
//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
While I've found posts on Stackoverflow that point to the use of individual boolean operators like not
, I开发者_如何学C can find nothing that explains how to combine them to filter text like this. What's the trick?
not() is a function in XPath, not an operator. You have to write:
//li[contains(text(), "memory") and not(contains(text(), "Graphics"))]
精彩评论