Xpath: select div that contains class AND whose specific child element contains text

后端 未结 4 1825
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 04:02

With the help of this SO question I have an almost working xpath:

//div[contains(@class, \'measure-tab\') and contains(., \'someText\')]

Ho

4条回答
  •  爱一瞬间的悲伤
    2020-12-13 04:34

    You can use ancestor. I find that this is easier to read because the element you are actually selecting is at the end of the path.

    //span[contains(text(),'someText')]/ancestor::div[contains(@class, 'measure-tab')]
    

提交回复
热议问题