Unable to check the checkbox in GEB

2019-07-29 22:05发布

I am trying to check my check box in Geb.

I have tried following codes, but no luck

$('input', type:'checkbox', id: 'chkTermsConditions', tabindex: '-1').value('true')
$(".CheckBoxUI").value('true')

Following is the HTML

enter image description here

After mouse go over the check box additional text updated (marked in the screen shot)

enter image description here

2条回答
地球回转人心会变
2楼-- · 2019-07-29 22:37

I managed to check the check box with $(".CheckBoxStyle").click()

Only issue is still Submit button doesn't get enable. Following is the html code for before and after checking the check box in real situation.

I tried the to click on the submit button with following code. It doesn't give any error. But still doesn't move to next page as expected.May be because of Submit button disable issue.

$("#submitBtnMsg").click()

Edited :

It was turned out above was application related issue. We have to click on the address after selecting via address validation service. Then only Submit button get enable.

$(".RedColor").click()
查看更多
Viruses.
3楼-- · 2019-07-29 22:44

You are attempting to check the box which has the attribute with value='true'

From the Geb manual:

The value of input, select and textarea elements can be retrieved and set with the value method. Calling value() with no arguments will return the String value of the first element in the Navigator. Calling value(value) will set the current value of all elements in the Navigator. The argument can be of any type and will be coerced to a String if necessary. The exceptions are that when setting a checkbox value the method expects a boolean (or, an existing checkbox value) and when setting a multiple select the method expects an array or Collection of values.

Try this:

$("#chkTermsConditions").value(true)

If you are using non standard HTML generated by some other platform. You may have to resort to clicking the element or using javascript.

The element that produces the desired click result could be one of the surrounding elements. If the widget is javascript controlled you may have to call a function that is embedded into the page for that widget. If its a javascript widget I cannot help you unless you can point me to a page which uses the same platform.

Try:

$('a[class=CheckRadioFocus]').click()

$('a[id=termLink]').click()

or any of the other surrounding elements.

查看更多
登录 后发表回答