,所以我有一個表,看起來像,只要有書,並在第一個列有清單是兩個鏈接,查看和刪除,爲每本書。
我希望能夠使用Watir查找指定書名的行並單擊該書的該視圖按鈕。
這裏是我迄今爲止
And /^click on View link of "(.*)" on the result set table$/ do |cell_name|
cellButton("submit.view", cell_name, "")
end
#
#
And /^click on Delete link of "(.*)" on the result set table with no_wait$/ do |cell_name|
cellButton("submit.delete", cell_name, "no_wait")
end
#
#
def cellButton(submit_type, s_name, s_wait_type)
c_found = 0
@browser.tables do |tbl|
tbl.rows do |r|
r.each do |c|
if c.text.to_s.matches(s_name)
c_found += 1
end
break if c_found > 0
end
if c_found > 0
if s_wait_type == "no_wait"
r.button(:name, submit_type).click_no_wait
else
r.button(:name, submit_type).click
end
end
break if c_found > 0
end
end
end
,這裏是針對特定視圖按鈕
<tr class="even">
<td class="actionColumn">
<span style="margin: 0px; padding: 0px; display: inline;">[</span>
<input id="013c6e2c8187_885b_1bd1f6fc" name="submit.view" class="action_link" size="" value="View" type="button" onclick="location.href='book_details.html'">
<span style="margin: 0px; padding: 0px; display: inline;">]</span><br>
<div>
<span style="margin: 0px; padding: 0px; display: inline;">[</span>
<input id="013c6e2c8187_1194_75ae28a8" name="submit.delete" class="action_link" size="" value="Delete" type="button">
<span style="margin: 0px; padding: 0px; display: inline;">]</span>
</div>
</td>
<td>
book title
<td>
<td>
more tds
</td>
</tr>
有當腳本運行沒有錯誤,但該視圖鏈接的HTML沒有按下。
我使用的Watir 4.0,紅寶石1.9.3和1.3.3黃瓜
一對夫婦的意見:1)我相信'click_no_wait'方法已過時(如果我沒有記錯的話);和2)按鈕上有'onclick'屬性,這意味着你可能不得不使用['fire_event'](http://rubydoc.info/gems/watir-webdriver/Watir/Element#fire_event-instance_method)方法。 – orde
當給出你正在使用的html例子時,給出所有相關的html是很重要的。給我們「鏈接」是很好的,因爲我們可以看到它實際上是一個看起來像鏈接的按鈕。但是,我們不知道表格的其餘部分是什麼樣的(即書名與該按鈕的關係如何)。 –
我添加了更多的html代碼,我還沒有機會看看你的答案呢。謝謝! – livelaughlove