java - 如何通过selenium Webdriver根据excel中给出的ID单击删除图标
问题描述
我有一个包含用户详细信息的表格的页面,我想在从 excel.Selenium Webdriver 检索 ID 时单击删除图标,而 java 用于执行相同操作。我正在使用此代码从 excel 中检索名称:-
data.getPatientID().get(rowCnt);
表格的 HTML 代码:-
<tr class="rgRow" id="ctl00_ContentPlaceHolder1_GridUserControl1_RadGrid1_ctl00__0">
<td>PAT 033</td>
<td><a id="ctl00_ContentPlaceHolder1_GridUserControl1_RadGrid1_ctl00_ctl04_lbtnLastname" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridUserControl1$RadGrid1$ctl00$ctl04$lbtnLastname','')">Bee</a></td>
<td> </td>
<td>Barry</td>
<td>(833)833-8338</td>
<td>Frisco</td>
<td>physician new </td>
<td><a onclick="if(!confirm('Do you want to delete this record'))return false;" id="ctl00_ContentPlaceHolder1_GridUserControl1_RadGrid1_ctl00_ctl04_Remove" class="closeBtn" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridUserControl1$RadGrid1$ctl00$ctl04$Remove','')"></a></td>
任何帮助将不胜感激。在此处输入图像描述
**** 中的文本是名称和删除按钮。
解决方案
根据您共享的HTML,单击删除图标,您可以创建一个函数,该函数将参数作为名称,例如Albert,然后单击相应的删除图标,如下所示:
public void clickDeleteIcon(String fname)
{
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='rgRow'][contains(@id,'_ContentPlaceHolder1_GridUserControl1_RadGrid1_')]//following::td[2]/a[.='" + fname + "']//following::a[1]"))).click();
}
现在单击删除图标,您可以调用clickDeleteIcon(String fname)
传递任何名称的函数,如下所示:
clickDeleteIcon("Albert");
//or
clickDeleteIcon("Bee")
推荐阅读
- javascript - myFunction querySelector,空白页
- r - 如何选择列,其中第一行等于 R 中的 TRUE?
- apache-spark - 了解 Spark 中的阶段
- terraform-provider-azure - Terraform - Azurerm - 订阅活动日志/API 日志记录
- javascript - JS函数结果不渲染
- jboss - 如何使用 IIB ESB 工具包从 Jboss JMS 队列中读取消息
- javascript - 跟踪服务器端的 readfile() 进度
- django - Django中的用户停用
- excel - 循环通过 10,000 个单元格时如何使 VBA 代码运行得更快?
- c++ - windows下如何使用子认证包登录?LsaLogonUser 调用失败,nt_status 0xC00000A7 (STATUS_BAD_VALIDATION_CLASS)