ano*_*Rey 2 c# selenium xpath selenium-webdriver
我想请求一些关于如何点击表格中的操作链接的帮助.
HTML页面如下所示.
Lebron James | EDIT | VIEW | DELETE
Chris Paul | EDIT | VIEW | DELETE
Carmelo Anthony | EDIT | VIEW | DELETE
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我在下面尝试了以下语法.
webDriver.FindElement(By.XPath("//td[contains(text(), 'Chris Paul')]" + webDriver.FindElement(By.CssSelector("//td/a[contains(href=\"/Player/Delete/)]")))).Click();webDriver.FindElement(ByXPath("//td[contains(text(), 'Carmelo Anthony')]//td/a(href="/Player/Delete")")).Click();上面的语法可能不适合我之前尝试过的但是它们看起来很相似.我能够在行中找到该名称,但我无法单击与该名称并行的操作链接.
你应该尝试使用xpath与following-sibling轴如下: -
点击Edit链接: -
webDriver.FindElement(By.XPath(".//td[text() = 'Lebron James']/following-sibling::td/a[text() = 'Edit']")).click();
Run Code Online (Sandbox Code Playgroud)点击View链接: -
webDriver.FindElement(By.XPath(".//td[text() = 'Lebron James']/following-sibling::td/a[text() = 'View']")).click();
Run Code Online (Sandbox Code Playgroud)点击Delete链接: -
webDriver.FindElement(By.XPath(".//td[text() = 'Lebron James']/following-sibling::td/a[text() = 'Delete']")).click();
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
842 次 |
| 最近记录: |