【问题标题】:How to find all <!--/noindex--> tags using xpath, ruby & webdriver?如何使用 xpath、ruby 和 webdriver 查找所有 <!--/noindex--> 标签?
【发布时间】:2015-02-25 14:40:33
【问题描述】:

xpath = //comment()[contains(.,'noindex')] 在 Selenium IDE 中为我工作,但使用 ruby​​ 和 webdriver 无法工作。 如何找到所有标签? 我正在尝试使用代码:

result = driver.find_elements(:xpath, "//comment()[contains(.,'noindex')]")
puts result

它返回 /var/lib/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok': invalid selector: 结果xpath 表达式 "//comment()[contains(.,'noindex')]" 是:[object Comment]。

html代码

<html xmlns="http://www.w3.org/1999/xhtml" class="">
<body class="siteBody">
<div class="wrapper">
    <div class="head">
        <div class="headIn">
            <div class="middleBlock">
                <!--noindex-->
                <!--/noindex-->
            </div>
        </div>
    </div>
</div>
<div class="foot">
    <div class="footerIn">
        <div class="footerBottomLeft">
            <div class="counters">
                <!--/noindex-->
                <!-- /Yandex.Metrika counter -->
                <!--/noindex-->
                <!--noindex-->
                <!--LiveInternet counter-->
                <!--/LiveInternet-->
                <!--/noindex-->
            </div>
        </div>
    </div>
</div>
</body></html>

【问题讨论】:

  • 能否分享部分或页面的html代码
  • 请在您的问题中加入一个最小的 HTML 示例。将我们指向一个链接并不是一个好主意,因为链接会中断,从而使您的问题对未来想要类似答案的人来说毫无用处。通过让他们转到该链接,这也浪费了那些会帮助您的人的时间。他们中的很多人会直接转向另一个问题。

标签: ruby-on-rails ruby selenium xpath selenium-webdriver


【解决方案1】:

分辨率为

result = @driver.find_elements(:xpath, "//*[comment()[contains(.,'noindex')]]").count

【讨论】:

    猜你喜欢
    • 2014-08-03
    • 1970-01-01
    • 2013-07-29
    • 2012-04-22
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 2018-08-28
    相关资源
    最近更新 更多