如何随机选择一个href链接的Watir

时间:2016-01-04 20:43:26

标签: ruby-on-rails watir

使用以下HTML我试图随机选择一个href链接

<div class="field">
<a href="/destinations/caribbean/british-virgin-islands/tortola-power-charter/availability">Check availability</a>
</div>
</div>
</div>
</div>
</article>
</div>
<div class="views-row views-row-3 views-row-odd views-row-last">
<article id="node-cruise-47" class="node node-cruise node-search-result node-cruise-search-result node-published node-not-promoted node-not-sticky author-admin odd clearfix s-search-result" itemscope="" itemtype="http://schema.org/Product">
<div class="search-result-inner clearfix">
<div class="s-search-result--left">
<div class="s-search-result--middle">
<div class="s-search-result--right">
<div class="field field-name-field-price field-type-number-decimal field-label-inline clearfix price-summary">
<div class="field field-name-field-departure-duration field-type-number-integer field-label-hidden price-conditions primary-condition">Based on 7 nights, yacht only</div>
<div class="availability-button-wrapper-search">
<div class="field">
<a href="/destinations/caribbean/british-virgin-islands/tortola-crewed-charter/availability">Check availability</a>

请注意,页面上不仅存在多个href链接。我使用以下代码

b.links(:xpath => '//div[@class="field"]/a').click 

但是我得到了:

"undefined method `click' for #<Watir::AnchorCollection:0x2ba1858> (NoMethodError)"

1 个答案:

答案 0 :(得分:3)