【问题标题】:Choosing not visible radio button选择不可见单选按钮
【发布时间】: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">&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 个单选按钮,我想选择其中一个。当我尝试使用方法 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 &lt;input id="id3" name="name" type="radio" value="2" style="position: absolute; opacity: 0;"&gt; is not clickable at point (604, 329). Other element would receive the click: &lt;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;"&gt;

标签: ruby web-scraping watir


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 这些按钮中的每一个都不存在,但它们存在。
    猜你喜欢
    • 2018-03-06
    • 2019-08-10
    • 1970-01-01
    • 2014-05-17
    • 2018-09-20
    • 2013-06-07
    • 2014-05-31
    • 2012-09-11
    • 1970-01-01
    相关资源
    最近更新 更多