我有一个不是“真实”复选框的复选框。CSS看起来像:
<li id="privileges:1" class="ui-tree-parent default" data-rowkey="1">
<div class="ui-tree-node ui-state-default" aria-checked="true" aria-selected="true" aria-expanded="true" role="treeitem">
<span class="ui-helper-clearfix ui-tree-node-content ui-corner-all ui-tree-selectable-node">
<span class="ui-tree-icon ui-icon ui-icon-triangle-1-s"></span>
<span></span>
<div class="ui-tree-checkbox ui-widget">
<div class="ui-tree-checkbox-box ui-widget ui-corner-all ui-state-default">
<span class="ui-tree-checkbox-icon ui-icon ui-icon-check"></span>
选中复选框时会出现最后一个跨度。
我的同事有以下代码,经过审查,它似乎是黑魔法,不应该验证任何东西:
WebElement checkedBox = findElementByXpath("//li[@id='privileges:1']/div[@aria-checked='true']/span/div/div");
@SuppressWarnings("unused")
Boolean isChecked;
isChecked = checkedBox.findElement(By.xpath("//li[@id='privileges:1']/div[@aria-checked='true']/span/div/div")).isSelected();
使用 Selenium2/Webdriver 检查复选框的最佳方法是什么?
这不起作用:
WebElement checkedBox = findElementByClass("//li[@id='privileges:1']/div/span/div/div/span[@class='ui-tree-checkbox-icon.ui-icon.ui-icon-check']");
assertTrue(checkedBox.isEnabled());
也没有:
WebElement checkedBox = findElementByClass("//li[@id='privileges:1']/div/span/div/div/span[@class='ui-tree-checkbox-icon.ui-icon.ui-icon-check']");
assertTrue(checkedBox.isDisplayed());