How to find element by attribute value in GPath?

后端 未结 4 1402
故里飘歌
故里飘歌 2021-02-18 18:35

What is an alternative to this XPath //div[@id=\'foo\'] in GPath? In general, where I can find this documentation?

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-18 18:47

    what you need is this:

    def root = new XmlSlurper().parseText(.toURL().text)
    
    def foundNode = root.'**'.find{ it.@id == "foo" }
    

    its the double * that will let you find it without knowing the path. At least this is how I do it.

提交回复
热议问题