尝试获取以下html的xpath/css

尝试获取以下html的xpath/css,css,xpath,selenium,Css,Xpath,Selenium,我正在尝试创建一个动态xpath或css定位器来定位、编辑和删除作为包含帐户信息的矩阵表的第一列的图像。每个帐户都有不同的电子邮件id,例如johng@teat.com在下面的html代码中 我正在寻找的是如何编写xpath/css定位器,允许我们根据已知的帐户电子邮件id单击编辑和删除图标/链接 <td nowrap="nowrap"><a href="#" onclick="$('table.jsonTable').matrix('remove',528); return

我正在尝试创建一个动态xpath或css定位器来定位、编辑和删除作为包含帐户信息的矩阵表的第一列的图像。每个帐户都有不同的电子邮件id,例如johng@teat.com在下面的html代码中

我正在寻找的是如何编写xpath/css定位器,允许我们根据已知的帐户电子邮件id单击编辑和删除图标/链接

<td nowrap="nowrap"><a href="#" onclick="$('table.jsonTable').matrix('remove',528); return false;" title="remove"><img src="sourcelocation/delete.png" alt="remove" style="border: 0px;"></a>&nbsp;<a href="#" onclick="return heClick(528);"><img src="sourcelocation/apedit.png" alt="view/edit" style="border: 0px;"></a></td><td>John</td><td>Ghoper</td><td>johng@test.com</td><td></td><td style="white-space: normal">Reports Viewer</td><td style="white-space: normal">test.com</td><td>never</td>
<td nowrap="nowrap"><a href="#" onclick="$('table.jsonTable').matrix('remove',302); return false;" title="remove"><img src="sourcelocation/delete.png" alt="remove" style="border: 0px;"></a>&nbsp;<a href="#" onclick="return heClick(302);"><img src="sourcelocation/apedit.png" alt="view/edit" style="border: 0px;"></a></td><td>Chris</td><td>Phela</td><td>kphela@test1.com</td><td></td><td style="white-space: normal">Reports Viewer</td><td style="white-space: normal">test1.com</td><td>never</td>
<td nowrap="nowrap"><a href="#" onclick="$('table.jsonTable').matrix('remove',528); return false;" title="remove"><img src="sourcelocation/delete.png" alt="remove" style="border: 0px;"></a>&nbsp;<a href="#" onclick="return heClick(890);"><img src="sourcelocation/apedit.png" alt="view/edit" style="border: 0px;"></a></td><td>John</td><td>Ghoper</td><td>Pattyg@test2.com</td><td></td><td style="white-space: normal">Reports Viewer</td><td style="white-space: normal">test2.com</td><td>never</td>
JohnGhoperjohng@test.comReportsViewertest.com从不
ChrisPhelakphela@test1.comReportsViewertest1.com从不
JohnGhoperPattyg@test2.comReportsViewertest2.com从不

我稍微修改了xml,使其格式良好。这是我的答案所依据的样本

<root>
  <td nowrap="nowrap">
<a href="#" onclick="$('table.jsonTable').matrix('remove',528); return false;"
    title="remove">
    <img src="sourcelocation/delete.png" alt="remove" style="border: 0px;" />
</a>
<a href="#" onclick="return heClick(528);">
    <img src="sourcelocation/apedit.png" alt="view/edit" style="border: 0px;" />
</a>
</td>
<td>John</td>
<td>Ghoper</td>
<td>johng@test.com</td>
<td></td>
<td style="white-space: normal">Reports Viewer</td>
<td style="white-space: normal">test.com</td>
<td>never</td>
<td nowrap="nowrap">
<a href="#" onclick="$('table.jsonTable').matrix('remove',302); return false;"
    title="remove">
    <img src="sourcelocation/delete.png" alt="remove" style="border: 0px;" />
</a>
<a href="#" onclick="return heClick(302);">
    <img src="sourcelocation/apedit.png" alt="view/edit" style="border: 0px;" />
</a>
</td>
<td>Chris</td>
<td>Phela</td>
<td>kphela@test1.com</td>
<td></td>
<td style="white-space: normal">Reports Viewer</td>
<td style="white-space: normal">test1.com</td>
<td>never</td>
<td nowrap="nowrap">
<a href="#" onclick="$('table.jsonTable').matrix('remove',528); return false;"
    title="remove">
    <img src="sourcelocation/delete.png" alt="remove" style="border: 0px;" />
</a>
<a href="#" onclick="return heClick(890);">
    <img src="sourcelocation/apedit.png" alt="view/edit" style="border: 0px;" />
</a>
</td>
<td>John</td>
<td>Ghoper</td>
<td>Pattyg@test2.com</td>
<td></td>

约翰
戈珀
johng@test.com
报表查看器
test.com
从未
克里斯
菲拉
kphela@test1.com
报表查看器
test1.com
从未
约翰
戈珀
Pattyg@test2.com

现在要根据已知的电子邮件id选择删除链接,您可以编写
//td[text()='johng@test.com']/previous sibling::td/a[@title='remove']

要根据已知的电子邮件id选择编辑图标,您可以编写
//td[text()='johng@test.com']/previous sibling::td/a/img[包含(@alt,'edit')]


希望这能有所帮助。

谢谢Vaman……我对您提供的xpath进行了一些修改,效果很好