单击带有xpath和Cumber的表中的编辑链接

单击带有xpath和Cumber的表中的编辑链接,xpath,cucumber,Xpath,Cucumber,如何使用cucumber单击使用xpath的表中项目列表中的编辑链接 我有一个选择器可以返回我需要的链接,但这是许多结果之一。。。。如何仅返回一个结果 这是我的黄瓜步骤 When /^I click the "([^\"]*)" link for "([^\"]*)"$/ do |link, cell_value| within "//*[.//td[contains(.,'#{cell_value}')] and .//a[text()='#{link}']]" do |scope|

如何使用cucumber单击使用xpath的表中项目列表中的编辑链接

我有一个选择器可以返回我需要的链接,但这是许多结果之一。。。。如何仅返回一个结果

这是我的黄瓜步骤

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
如您所见,这将起作用,但只需单击表中的第一个编辑链接,即使它知道已匹配的其他链接。。。所以这不好

以下是表格和选择器:

谢谢大家!

这也是该文件的来源,以防服务关闭或不支持链接到外部代码

## 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 &nbsp;&nbsp;&nbsp;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']]
##HTML源表
名称
启用
做尼古丁测试吗
行动
微软
对
不
国际商用机器公司
对
不
##XPath选择器(不工作)正在尝试以此链接为目标:(表中的第二个编辑链接)
//*[.//text()='IBM'和//a[text()='Edit']]
您的xpath正则表达式(“//*[.//td[contains(,,,,,,,,,,,,,,,,,,,,,,,,,,[text()='.{link}']])以数组的形式返回多个“scope”,因此您可以通过指定元素来指定要使用的“scope”: 作用域[0]。单击链接作为第一个作用域 作用域[1]。单击第二个

xpath正则表达式(//*[.//td[contains(,'.{cell{u value}'))和//一个[text()='.{link}]]以数组的形式返回多个“作用域”,因此可以通过指定元素来指定要使用的作用域: 作用域[0]。单击链接作为第一个作用域
作用域[1]。第二个

需要选择什么是XML文档以及其中的具体内容?请在你的问题中提供足够的信息。迪米特,你有没有看我那里的pastie链接?其中列出了我正在使用的当前xpath选择器的完整内容。如果您查看它,您可以看到我正在尝试选择中的“编辑”链接,该链接的文本为“IBM”。如果我的问题还不清楚,请告诉我。谢谢这里有一个相关的问题/答案:什么是XML文档,需要选择其中的哪些内容?请在你的问题中提供足够的信息。迪米特,你有没有看我那里的pastie链接?其中列出了我正在使用的当前xpath选择器的完整内容。如果您查看它,您可以看到我正在尝试选择中的“编辑”链接,该链接的文本为“IBM”。如果我的问题还不清楚,请告诉我。谢谢这里有一个相关的问题/答案: