Xpath error with not() and ends-with()

前端 未结 4 1898
时光说笑
时光说笑 2021-01-05 11:58

I have the following Xpath expression:

//*[not(input)][ends-with(@*, \'Copyright\')]

I expect it to give me all elements - except input - w

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 12:21

    I don't know Selenium but if //*[not(input)][starts-with(@*, 'Copyright')] is parsed successfully and if additionally the XPath 2.0 function ends-with is supported then I don't see any reason why //*[not(input)][ends-with(@*, 'Copyright')] is not accepted as a legal expression. Your verbal description however sounds as if you want //*[not(self::input)][@*[ends-with(., 'Copyright')]].

    //*[not(input)] selects any elements not having any input child element while //*[not(self::input)] selects any elements not being themselves input elements. As for comparing [@*[ends-with(., 'Copyright')]] with what you have, my suggestion is true as long as there is any attribute node which ends with 'Copyright' while your test would only work if there is a single attribute which ends with 'Copyright', as ends-with http://www.w3.org/TR/xquery-operators/#func-ends-with allow a sequence with a single item as its first argument or an empty sequence but not several items.

提交回复
热议问题