使用python的Selenium web自动化:如何使用Selenium处理表,通过匹配文本来查找特定行并删除该行



下面是一段代码,我已经复制了一条记录(行(。我想从下面的代码中搜索selenium1,并删除该表的记录。我已经分享了记录在表格中的截图。每个记录的ID也不同。所以,我想删除基于匹配文本的记录。请帮助

<tr class="evenrow" id="S2D10925" onmouseover="javascript:this.className='hilightrow';" onmouseout="javascript:this.className='evenrow';" onclick="javascript:selectNode('S2D10925');">
<td align="left">
&nbsp;
<img src="../images/icons/destinationsemail3.png" style="vertical-align:middle;" width="16" 
height="16">&nbsp;
SELENIUM1
</td>
<td nowrap="nowrap" align="left">Automation1</td>
<td nowrap="nowrap" align="left">INTERNET</td>
<td nowrap="nowrap" align="left">INTER_PROVIDER</td>
<td align="left">SELENIUM1@SEQENT.COM</td>
<td align="left">selenium1@seqent.com</td>
<td align="left">EMAIL</td>
<td nowrap="nowrap" align="left">(UTC-10:00) Hawaii</td>
<td nowrap="nowrap" align="left">Enabled</td>
</tr>

在此处输入图像描述

我会选择XPath。实现将根据您使用的库而有所不同,但XPath是由底层Webdriver支持的。

示例XPath,它将使tr节点包含给定文本的td

//tr[//td[contains(text(),'Automation1')]]

这是一个使用html片段的Codepen:

https://codepen.io/chm-dev-the-selector/pen/dyVdLOa

如果您不熟悉XPath,我强烈推荐使用此资源:https://devhints.io/xpath如果您想开门见山,我发现这是一种非常有用且时效性强的资源,尤其是使用XPath测试床(在页面上提供(。

在类似的主题中也发现了这一点:https://www.guru99.com/using-contains-sbiling-ancestor-to-find-element-in-selenium.html

最新更新