【发布时间】:2019-01-16 15:15:04
【问题描述】:
我正在使用 ruby 2.5.1、watir 6.11、Chrome 68.0、chrome webdriver 2.40 进行网络抓取,但我在选择单选按钮时遇到了问题。我页面的 Html 代码如下所示:
<tr> <td class="filtr-info"> </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"> </td>
<td> </td>
</tr>
所以,我有 3 个单选按钮,我想选择其中一个。当我尝试使用方法 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
如果按钮仅存在但不可见或不存在,我有什么方法可以选择它们?
【问题讨论】:
-
它是正确的 HTML 吗?因为单选按钮的样式属性将所有单选按钮一个接一个地放在同一位置。当我删除样式属性时,我可以分别查看三个单选按钮。
-
@Rajagopalan 我已经编辑了原始帖子-现在您可以使用正确的 HTML 进行检查。
-
我尝试使用你的代码,我没有遇到任何错误。首先更新整个错误消息,其次,获取这个 html sn-p 并尝试打开文件并查看它的外观。因为没有一个单选按钮甚至不在外观中。或者你能给我网址吗?
-
@Rajagopalan 我无法提供网址,因为该网站需要登录并且是付费服务。
-
@Rajagopalan 整个错误:` C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.13.1/lib/selenium/webdriver/remote/response .rb:69:in
assert_ok': unknown error: Element <input id="id3" name="name" type="radio" value="2" style="position: absolute; opacity: 0;"> is not clickable at point (604, 329). Other element would receive the click: <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;">
标签: ruby web-scraping watir