问题
I cannot get the checkbox
selector from the documentation working. Any idea why? $('checkbox').size()
is always zero.
HTML page
<html>
<head>
<title>Geb</title>
</head>
<body>
<input type="checkbox" name="pet" value="dogs" checked="true" />
</body>
</html>
Groovy code
Browser.drive {
go "file:///home/zoran/page.html"
println $('checkbox').size() // is always zero
}
回答1:
To select all checkboxes on a page using a jQuery selector you need to use:
$('input[type=checkbox]').size()
回答2:
to select all checkboxes use jquery selector as
$('input:checkbox').size()
回答3:
simply provide id to your checkbox
<input type="checkbox" id="chkPet" name="pet" value="dogs" checked="true" />
and then
$("#chkPet")
来源:https://stackoverflow.com/questions/18848429/cannot-get-a-checkbox