Geb更改属性值

时间:2016-04-14 06:25:29

标签: selenium spock geb

我想知道更改geb(selenium)中元素的任何属性值的正确方法是什么。

例如,我有这个元素:

static content = {
    radioSelect(wait: true) { $('input[name=rr]')}
}

现在我要设置任何属性。我没有找到一个好的方法,我使用这个解决方法:

(driver as JavascriptExecutor).executeScript( "document.getElementsByName('rr')[0].setAttribute('checked', true)" )

还有其他方法吗?喜欢radioSelect.setAttribute?

1 个答案:

答案 0 :(得分:2)

使用Geb提供的jQuery integration

radioSelect.jquery.attr("checked", true)

这相当于

js.exec 'jQuery("input[name=rr]").attr("checked", true)'

但要小心:

  

jQuery集成仅在您使用的页面时才有效   包含jQuery,Geb不会在页面中为您安装它。该   jQuery的最低支持版本是1.4。

相关问题