如果我能在同一行上找到文本字符串,如何识别表中的复选框

本文关键字:何识别 字符串 识别 复选框 文本 如果 一行 | 更新日期: 2023-09-27 18:37:13

我正在尝试修复一个损坏的测试。我正在使用VS2010 C#和Webaii(Telerik)来自动化测试。

我在网页中有一个表格,有 10 行(带分页),每行包含 10 列(假设列名称为 A、B、C、D、E...)在"C"列中有一个复选框(没有标签),列"E"有一个超链接,下面是代码,当我运行时它找不到应用程序编号旁边的复选框

string applicationNumber="A2341"
StringBuilder buffer = new StringBuilder();
buffer.Append("//a[contains(text(),'").Append(applicationNumber).Append("')]/../..//input[@type='checkbox']");
Generic.Find.ByXPath<HtmlInputCheckBox>(buffer.ToString()).Check(true, true); 
当我运行时,它无法找到应用程序编号旁边的复选框,

但是如果我使用以下代码,那么在该页面上它会单击第一个复选框,而不是与我的应用程序编号对应的复选框

Generic.Find.ByXPath<HtmlInputCheckBox>("//input[contains(@type,'"checkbox'")]").Check(true, true);

我的代码有什么问题

如果我能在同一行上找到文本字符串,如何识别表中的复选框

我的解决方案是

StringBuilder buffer = new StringBuilder();
buffer.Append("//a[contains(text(),'").Append(applicationNumber + "')]");
String id = Generic.Find.ByXPath(buffer.ToString()).IdAttributeValue.Split(new char[] { ':' })[2];
Generic.Find.ById<HtmlInputCheckBox>("dashboardForm:applicationTaskTable:" + id + ":application_checkbox").Check(true, true);