Retrieve an xpath text contains using text()

前端 未结 1 474
梦如初夏
梦如初夏 2020-12-08 00:50

I\'ve been hacking away at this one for hours and I just can\'t figure it out. Using XPath to find text values is tricky and this problem has too many moving parts.

相关标签:
1条回答
  • 2020-12-08 01:25

    text() gets you a set of text nodes. I tend to use it more in a context of //span//text() or something.

    If you are trying to check if the text inside an element contains something you should use contains on the element rather than the result of text() like this:

    span[contains(., 'testuser')]
    

    XPath is pretty good with context. If you know exactly what text a node should have you can do:

    span[.='full text in this span']
    

    But if you want to do something like regular expressions (using exslt for example) you'll need to use the string() function:

    span[regexp:test(string(.), 'testuser')]
    
    0 讨论(0)
提交回复
热议问题