如何在GEB自动化中单击单选按钮

时间:2018-03-08 13:06:43

标签: grails geb

我尝试使用

$(".formName .className").click()

$(".formName .className").value("MALE")

但这些都不起作用

4 个答案:

答案 0 :(得分:0)

您可以尝试通过名称属性

选择它
$('input', name: 'gender').value('MALE')

答案 1 :(得分:0)

我建议使用Geb Modules。它们使得与许多输入的交互变得轻而易举并且非常易读。例如:使用Radio Buttons

鉴于html ......

<html>
    <body>
        <label for="site-current">Search this site</label>
        <input type="radio" id="site-current" name="site" value="current">

        <label for="site-google">Search Google
            <input type="radio" id="site-google" name="site" value="google">
        </label>
    </body>
</html>

可以这样使用......

def radios = $(name: "site").module(RadioButtons)
radios.checked = "current"

assert radios.checked == "current"
assert radios.checkedLabel == "Search this site"

radios.checked = "Search Google"

assert radios.checked == "google"
assert radios.checkedLabel == "Search Google"

答案 2 :(得分:0)

点击使用Geb的单选按钮应该没有什么复杂的。

使用选择器定义按钮:

static content = {
  myRadioButton{ $('#RadioButton') }
}

然后简单地致电:

myRadioButton.click()

答案 3 :(得分:0)

假设。.您有一个单选按钮

 <input type="radio" name="radioBtn" value="1"/>
  <input type="radio" name="radioBtn" value="1"/>

    def radioBtnClick(def radioValue){
         $("input[name='radioBtn']").value radioValue
    }

这肯定可以解决您的问题 “快乐编码”

相关问题