1
如何使用黃瓜單擊xpath中表格中的項目列表中的編輯鏈接?點擊xpath和黃瓜表中的編輯鏈接
我有一個選擇器工作,返回我需要的鏈接,但它是許多結果之一....我怎麼能只返回1結果?
這是我的黃瓜步
When /^I click the "([^\"]*)" link for "([^\"]*)"$/ do |link, cell_value|
within "//*[.//td[contains(.,'#{cell_value}')] and .//a[text()='#{link}']]" do |scope|
scope.click_link link
end
end
正如你可以看到這會工作,但只需點擊表格中的第一個編輯鏈接,即使它知道,它已經匹配了別人......所以那不好。
下面是表和選擇:http://pastie.textmate.org/private/9od335pmsj4hi9nbe9lbow
謝謝!
這是該文件的來源,以防萬一服務停止或鏈接到外部代碼時被忽視。
## HTML source table
<table>
<tr>
<th>
Name
</th>
<th>
Enabled
</th>
<th>
Does Nicotine Testing
</th>
<th colspan='3'>
Actions
</th>
</tr>
<tr>
<td nowrap='nowrap'>
Microsoft
</td>
<td>
Yes
</td>
<td>
No
</td>
<td nowrap='nowrap'>
<a href="/employers/407">Show Portal</a>
</td>
<td>
<a href="/employers/407/edit">Edit</a>
</td>
<td>
<a href="/employers/407" onclick="if (confirm('Are you sure you want to delete the employer \'Microsoft\'? \n\nAll of this employer\'s locations will be deleted which include: \n \nAll users associations to those locations will also be removed. \n\nThere is NO UNDO. Proceed?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete</a>
</td>
</tr>
<tr>
<td nowrap='nowrap'>
IBM
</td>
<td>
Yes
</td>
<td>
No
</td>
<td nowrap='nowrap'>
<a href="/employers/406">Show Portal</a>
</td>
<td>
<a href="/employers/406/edit">Edit</a>
</td>
<td>
<a href="/employers/406" onclick="if (confirm('Are you sure you want to delete the employer \'IBM\'? \n\nAll of this employer\'s locations will be deleted which include: \n 1) appleton\n \nAll users associations to those locations will also be removed. \n\nThere is NO UNDO. Proceed?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete</a>
</td>
</tr>
</table>
## XPath Selector (not working) trying to target this link: <a href="/employers/406/edit">Edit</a> (the 2nd edit link in the table)
//*[.//text()='IBM' and .//a[text()='Edit']]
什麼是XML文檔,究竟需要選擇什麼?請在您的問題中提供足夠的信息。 – 2010-05-10 20:28:44
Dimitre,你看過我在那裏的pastie鏈接嗎?它具有完整的
這裏有一個相關的問題/答案: http://stackoverflow.com/questions/4248889/cucumber-selecting-an-element-from-a-table-for-deletion-or-addition/7618578# 7618578 – mongo296 2011-10-01 06:32:54
回答
你的XPath正則表達式(「//*[.//td[contains(.,'#{cell_value} ')]和.//a[text()='#{link}'] ]「)以數組的形式返回多個」範圍「,因此您可以通過指定元素來指定使用哪一個: scope [0] .click_link第一個鏈接# 範圍[1] .click_link第二個鏈接#
來源
2010-08-11 14:12:33 hemal
相關問題