GEB:如果是NonEmptyNavigator,我如何删除子元素?

时间:2014-09-28 17:54:35

标签: geb

以下HTML:

<h1>
    "Bison 120"
    <span class="prise1">#1429</span>
</h1>

我需要从H1中提取准确的文字 - “Bison 120” .text()的结果是:“Bison 120#1429”

与此案非常相似:Using .text() to retrieve only text not nested in child tags 但是在GEB中,为jQuery提出的解决方案不起作用。

我目前的解决方案 - 从H1元素中移除子元素。 您能否帮我解决如何在GEB中移除儿童的问题。

提前谢谢!

1 个答案:

答案 0 :(得分:1)

您只需获取父文本,然后从中减去所有子项的文本:

def h1 = $("h1")

def h1Text = h1.children().inject(h1.text()) { text, child ->
    text - child.text()
}
相关问题