Selenium:如何断言所有复选框已选中?
Decimal totalCheckboxes = selenium.GetXpathCount("//input[@type='checkbox']");
for (int i = 1; i < totalCheckboxes + 1; i++)
{
// Assert attempt 1
//Assert.IsTrue(selenium.IsChecked("/descendant-or-self::input[@type='checkbox'][" + i + "]"));
// Assert attempt 2
//Assert.IsTrue(selenium.IsChecked("//input[@type='checkbox'][" + i + "]"));
}
我需要断言多个复选框已被选中。复选框的数量并不总是固定的,因为它们取决于我的搜索条件。此外,复选框具有不同的 ID 和名称。例如,对于第一个复选框,id = "ctl07_ctl01_ctl01_cbxRepeater_e5962e80-ca07-42e3-908f-1217ef5787d4" name = “ctl07$ctl01$ctl01$cbxRepeater_e5962e80-ca07-42e3-908f-1217ef5787d4”
对于第二个复选框, id =“ctl07_ctl01_ctl03_cbxRepeater_c094f428-7ead-4ded-a11b-5824be49a95b”名称=“ctl07$ctl01$ctl03$cbxRepeater_c094f428-7ead-4ded-a11b-5824be49a95b”
等等对于以下复选框。
我已经尝试了多种方法来添加断言来断言复选框已选中(上面的断言尝试 1 和断言尝试 2),但是当我运行测试时,它仍然失败。我得到的错误:
Selenium.SeleniumException: ERROR: Element /descendant-or-self::input[@type='checkbox'][1] not found
Selenium.SeleniumException: ERROR: Element //input[@type='checkbox'][2] not found
对此的任何帮助将不胜感激。提前致谢!
Decimal totalCheckboxes = selenium.GetXpathCount("//input[@type='checkbox']");
for (int i = 1; i < totalCheckboxes + 1; i++)
{
// Assert attempt 1
//Assert.IsTrue(selenium.IsChecked("/descendant-or-self::input[@type='checkbox'][" + i + "]"));
// Assert attempt 2
//Assert.IsTrue(selenium.IsChecked("//input[@type='checkbox'][" + i + "]"));
}
I need to assert multiple checkboxes are checked. The number of checkboxes are not always fixed because they depend on my search criteria. Also, the checkboxes have different id and name. For example, for the first checkbox, id = "ctl07_ctl01_ctl01_cbxRepeater_e5962e80-ca07-42e3-908f-1217ef5787d4" name = "ctl07$ctl01$ctl01$cbxRepeater_e5962e80-ca07-42e3-908f-1217ef5787d4"
and for the second checkbox, id="ctl07_ctl01_ctl03_cbxRepeater_c094f428-7ead-4ded-a11b-5824be49a95b" name="ctl07$ctl01$ctl03$cbxRepeater_c094f428-7ead-4ded-a11b-5824be49a95b"
and so on for the following checkboxes.
I have tried several things to add an assertion to assert the checkboxes are checked (Assert attempt 1 and Assert attempt 2 above), but when I run the test, it still fails at that point. Ther error I get:
Selenium.SeleniumException: ERROR: Element /descendant-or-self::input[@type='checkbox'][1] not found
Selenium.SeleniumException: ERROR: Element //input[@type='checkbox'][2] not found
Any help on this would be highly appreciated. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
注意添加
()
。()
表示首先评估我(如您所料)。这允许您执行(...)[1]
来查找在()
中计算的 xpath 的第一个元素。Try :
Note the addition of
()
.The
()
says evaluate me first (as you would expect). This allows you to do(...)[1]
to find the first element of the xpath evaluated in the()
.