Reputation: 309
How do I click a hidden checkbox and/or change the value of a hidden element (from "2" to "1") using ruby and watir?
The html
[div class="spec"]
[span class="listheader"]Rechtsgebieden[/span]
[div]
[span class="legalarea" style="cursor:default" onmouseout="hlt(this,false);" onmouseover="hlt(this,true);" ondblclick="call(this, '.legalarea');" onclick="call(this, '.legalarea');"]
[table id="ctl00_cphMC_SS_eJuris_fltrJurLegalArea_cbt" border="0"] [/table]
[/div]
[span class="legalarea-root " style="cursor:default" onmouseout="hlt(this,false);" onmouseover="hlt(this,true);"]
[div id="ctl00_cphMC_SS_eJuris_fltrJurLegalArea_qwtA105qwausqwt_pu" class="CheckboxValuePopup" style="display:none;position:absolute;" name="ctl00-cphMC-SS-eJuris-fltrJurLegalArea-qwtA105qwausqwt-pu"] [/div]
[span class="legalarea-root " style="cursor:default" onmouseout="hlt(this,false);" onmouseover="hlt(this,true);"]
[input id="ctl00_cphMC_SS_eJuris_fltrJurLegalArea_qwtA109qwausqwt_cb_cv" type="hidden" value="2" name="ctl00$cphMC$SS$eJuris$fltrJurLegalArea$qwtA109qwausqwt$cb_cv"]
[img ondblclick="CheckBox(this, '.ctl00-cphMC-SS-eJuris-fltrJurLegalArea-qwtA109qwausqwt-pu', true);" onclick="CheckBox(this, '.ctl00-cphMC-SS-eJuris-fltrJurLegalArea-qwtA109qwausqwt-pu', true);" src="http://portal.rechtsorde.nl/img/2.png"]
[a class="search-filter-link" onclick="$('.ctl00-cphMC-SS-eJuris-fltrJurLegalArea-qwtA109qwausqwt-pu').dialog('open'); callerID=this;"]Handels- en ondernemingsrecht[/a]
The code that works to access the element/find the value:
browser.hidden(:name, /A111/)first.value
Upvotes: 0
Views: 1560
Reputation: 46
you can use the JS to change the value
browser.execute_script('document.getElementById("ctl00_cphMC_SS_eJuris_fltrJurLegalArea_qwtA109qwausqwt_cb_cv").value = "1"')
Upvotes: 3
Reputation: 46846
Watir does not allow you to change the values of hidden elements. Watir is attempting to simulate an actual user. Since users cannot change the hidden element, neither can Watir. Instead, you should be trying to interact with the element that call the function to change the hidden element.
The html provided seems a bit awkward (see comment on question), but my guess is that the hidden value changes when clicking the img that looks like a blank checkbox field.
You could try clicking the image that is a sibling to the hidden field:
browser.hidden(:name, /A111/).first.parent.img.click
Given that the name of the hidden field appears to be dynamically generated, you might want to also try the following (which I think are based on the parts less likely to change):
#Assuming that the link text beside the checkbox is unique
browser.link(:text => 'Handels- en ondernemingsrecht').parent.img.click
#Assuming that there is only one hidden element with 'fltrJurLegalArea' in the name:
browser.hidden(:name, /fltrJurLegalArea/).first.parent.img.click
Upvotes: 3