简体   繁体   中英

Click button with Watir can't find button

Trying to test a poll vote with Watir. Just using a script at the moment, and I can't get the script to find the correct button.

HTML (reformatted slightly for readability)

<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>

My method for the click action:

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

Based on your HTML, you should try:

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

or

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

In your vote method, you are trying to locate a span within a table cell (instead of a link with a class attribute).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM