1
試圖用Watir測試投票表決。此刻只需使用腳本,我無法使腳本找到正確的按鈕。用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="http://www.url.com/news/world-news/protective-dad-makes-daughter-wear-5568808#_3";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
注意將來,發佈涵蓋代碼中所用內容的HTML是很有幫助的。在上面的代碼中,您嘗試使用表和跨度,但是您的html僅用於鏈接,沒有任何上下文至於如何與您的代碼中的表或跨度相關聯。 –