开发者

Correct syntax for including boolean expressions in XPath; specifically not & and

开发者 https://www.devze.com 2023-03-25 09:43 出处:网络
In order to find <li> elements that contain the text \"memory\" but not the text \"Graphics\", I have tried a dozen variation of:

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

精彩评论

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

关注公众号