点击按钮,Watir无法找到按钮

时间:2015-04-23 22:46:37

标签: ruby watir watir-webdriver

尝试使用Watir测试投票。目前只使用脚本,我无法让脚本找到正确的按钮。

HTML(为了便于阅读而略微重新格式化)

<a href="#" class="btn-poll-short" 
            data-action-url="http://url.com/poll/vote.do" 
            data-svar="svar1" 
            data-type="picture_5569154" 
            data-action="a:1" data-socialpollanswer="Yes" 
            data-pollid="5569154" 
            data-shareanswerpicture=""
            onclick="s_objectID=&quot;http://www.url.com/news/world-news/protective-dad-makes-daughter-wear-5568808#_3&quot;;return this.s_oc?this.s_oc(e):true">

                Yes
</a>

我点击操作的方法:

def vote
    browser = Watir::Browser.new
    browser.goto 'http://www.url.com/news/world-news/protective-dad-makes-daughter-wear-5568808'
    sleep 5
    browser.td(:class => 'btn-poll-short').span(:id => 'Yes').click
end

1 个答案:

答案 0 :(得分:1)

根据您的HTML,您应该尝试:

browser.link(:class => 'btn-poll-short').click

browser.link(:text => 'Yes').click

vote方法中,您试图在表格单元格中找到一个范围(而不是具有类属性的链接)。