0

ruby と watir を使用して、非表示のチェックボックスをクリックしたり、非表示の要素の値を ("2" から "1" に) 変更したりするにはどうすればよいですか?

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]

要素にアクセスする/値を見つけるために機能するコード:

browser.hidden(:name, /A111/)first.value 
4

2 に答える 2

3

Watir では、隠し要素の値を変更することはできません。Watir は実際のユーザーをシミュレートしようとしています。ユーザーは隠し要素を変更できないため、Watir も変更できません。代わりに、関数を呼び出して非表示の要素を変更する要素とやり取りする必要があります。

提供された html は少しぎこちないように見えますが (質問のコメントを参照)、空白のチェックボックス フィールドのように見える img をクリックすると、非表示の値が変更されると思います。

非表示フィールドの兄弟である画像をクリックしてみてください。

browser.hidden(:name, /A111/).first.parent.img.click

非表示フィールドの名前が動的に生成されているように見える場合は、次のことも試してみてください (変更される可能性が低い部分に基づいていると思います)。

#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
于 2013-02-21T17:42:23.070 に答える