geb过滤链接的内容

时间:2015-05-22 11:42:36

标签: groovy automation geb

我有一堆包含超链接的页面。我希望geb浏览器自动化套件按其显示值过滤特定链接。我可以做如下,它的工作原理。

        def links = $("a")
        def a =[]
        links.each {
            if (it.text() == "blah blah blah....") {
                a.add(it)
            }
        }
        //do something with a

有没有更好的方法来做到这一点。也许过滤()。但我似乎无法让它发挥作用。

由于 Sajith

1 个答案:

答案 0 :(得分:3)

您可以在Geb中选择文字:

$("a", text: "blah blah blah...")

如果您想重复使用选择器并按文字过滤,那么您确实可以使用filter()

def links = $("a")
def linksWithText = a.filter(text: "blah blah blah...")