geb - 获取 Geb 中的输入类型

标签 geb

我正在使用 Geb 编写一个脚本,该脚本将使用随机输入多次测试调查,以确保没有任何中断。我想迭代表单上的每个输入,并根据输入类型执行不同的操作。

例如:

while ($("form").find("input", j)) {
    if($("form").find("input", j) == "checkbox"){
        //check it sometimes
    }
    else if($("form").find("input", j) == "select"){
        //select a random option
    }
    j++
}

我还不太确定调查将如何进行,所以我宁愿像人类一样向下浏览页面,而不是先做所有复选框,然后再选择所有选项等。可以检查调查的类型像我的例子一样输入?

此外,我注意到我正在重复 $("form").find("input", j)。我可以像 jQuery 那样将它变成一个变量吗?

最佳答案

只需在导航器中收集所有输入选择,然后迭代所有这些即可。使用 is(String tagName) 检测选择元素,使用 @type 属性访问器检测其他元素类型:

def form = $("form")
def formElements = form.find("input") + form.find("select")
formElements.each { Navigator element ->
    if (element.is("select") {
        //select a random option
    }
    if (element.@type == "checkbox") {
        //check it sometimes
    }
}

关于geb - 获取 Geb 中的输入类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26088498/

相关文章:

testing - GEB 找到第一个可见元素

gradle - geb.Browser尝试使用FirefoxDriver代替PhatomJSDriver

grails - 无法使用 AnglurJS 和 Geb 设置输入文本字段

grails - 测试受 Spring 安全保护的页面

Geb:text() 与 value()

grails - Geb:元素不再附加到 waitFor 内的 DOM

testing - 如何让 WebDriver 解除 Firefox 安全警报?

hudson - 无法运行Webdriver测试,Hudson永远挂起

testing - 根据环境执行特定的 Geb 测试

grails - 如何在GEB中选择标签文本?