开发者

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"))]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜