选择不可见的单选按钮

Choosing not visible radio button

我正在使用 ruby 2.5.1,watir 6.11,Chrome 68.0,chrome webdriver 2.40 进行网络抓取,我遇到了 selecting 单选按钮。 Html 我页面的代码如下:

<tr> <td class="filtr-info">&nbsp;</td>
<td class="filtr-content-radio">
<div class="iradio_square-grey checked" style="position: relative;">
<input id="id1" name="name" type="radio" value="0" checked="checked" style="position: absolute; opacity: 0;">  
<ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0; cursor: pointer;">
</ins></div>
<span class="filter-radio-name">KRS</span>
<div class="iradio_square-grey" style="position: relative;">
<input id="id2" name="name" type="radio" value="1" style="position: absolute; opacity: 0;">
<ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0; cursor: pointer;">
</ins></div>
<span class="filter-radio-name">REGON</span>
<div class="iradio_square-grey" style="position: relative;">
<input id="id3" name="name" type="radio" value="2" style="position: absolute; opacity: 0;">
<ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0; cursor: pointer;">
</ins></div>
<span class="filter-radio-name">NIP</span>
</td>
<td class="filtr-help">&nbsp;</td>
<td>&nbsp;</td>
</tr>

所以,我有 3 个单选按钮,想要 select 其中一个。当我尝试使用方法 set 时出现以下错误:

unknown error: Element <input id="id1" name="name" type="radio" value="1" style="position: absolute; opacity: 0;"> is not clickable at point (623, 245).

我还尝试了一些方法来检查 watir 如何看待这些按钮:

$b.radio(:id,'id1').exists? => true
$b.radio(:id,'id1').present? => false
$b.radio(:id,'id1').visible? => false
$b.radio(:id,'id1').hidden? => false

如果按钮仅存在但不可见或不存在,我是否可以选择其中一个按钮?

您可以遍历单选按钮,检查它是 present? 然后是 clickset

['id1', 'id2', 'id3'].each do |el_id|
   el = $b.radio(id: el_id)
   el.click if el.present?
end

由于 ins 元素覆盖了您的元素,我认为它在您的 html 中是永久性的,您最好执行此单击,我希望它会起作用。

b.radio(id: 'id2').following_sibling.click