Xpath: Find element with class that contains spaces

前端 未结 1 391
甜味超标
甜味超标 2021-01-14 23:10

So I have elements that look like this

  • # note the space
  • 1条回答
    •  旧时难觅i
      2021-01-14 23:49

      This XPath 1.0 expression,

      //li[contains(concat(' ', normalize-space(@class), ' '),
                    ' attribute ')]
      

      will select all li elements with class attributes that contain the attribute substring, regardless of whether it has leading or trailing spaces.


      If you only want to match attribute with possible leading and trailing spaces only (no other string values), just use normalize-space():

      //li[normalize-space(@class) = 'attribute']
      

      0 讨论(0)
    提交回复
    热议问题