我想寻求一些帮助,了解如何单击表格中的操作链接。
HTML 页面如下所示。
Lebron James | EDIT | VIEW | DELETE
Chris Paul | EDIT | VIEW | DELETE
Carmelo Anthony | EDIT | VIEW | DELETE
html 格式如下所示。
<tr>
<td>Lebron James</td>
<td>
<a href="/Player/Edit/282">Edit</a>
<a href="/Player/View/282">View</a>
<a href="/Player/Delete/282">Delete</a>
</td>
</tr>
我已经尝试了下面的语法。
webDriver.FindElement(By.XPath("//td[contains(text(), 'Chris Paul')]"
+webDriver.FindElement(By.CssSelector("//td/a[包含(href=\"/Player/Delete/)]"))).Click();
webDriver.FindElement(ByXPath("//td[contains(text(), 'Carmelo Anthony')]//td/a(href="/Player/Delete")")).Click( );
上面的语法可能与我之前尝试过的不准确,但它们看起来很相似。我能够在行中找到名称,但无法单击与名称平行的操作链接。
最佳答案
您应该尝试将 xpath
与 following-sibling
axes 一起使用如下:-
点击
编辑
链接:-webDriver.FindElement(By.XPath(".//td[text() = 'Lebron James']/following-sibling::td/a[text() = 'Edit']")).click();
点击
查看
链接:-webDriver.FindElement(By.XPath(".//td[text() = 'Lebron James']/following-sibling::td/a[text() = 'View']")).click();
点击
删除
链接:-webDriver.FindElement(By.XPath(".//td[text() = 'Lebron James']/following-sibling::td/a[text() = 'Delete']")).click();
关于c# - 使用 selenium C# 在一行中单击操作链接(删除、查看、编辑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39624719/