今天为了uncheck一个checkbox,工作了一天。html是这样的:
=========================The html========================================
<TR id=reportColumn_2000343240 onmouseout=lowlightRow(this);>
<TD><INPUT this)" CHECKED type=checkbox> Total time </INPUT>*
</TD>
</TR>
首先先用WebDriver定位这个checkbox: 使用contains这个函数,找到TD标签,它的text包含column(这个是一个String变量)。注意checkbox是要定位到input这个标签的。
WebElement checkbox=Browser.getDriver().findElement(By.xpath("//FORM[@id='reportColumnForm']/DIV/TABLE/TBODY/TR/TD[contains(.,'" + column + "')]/INPUT[@type='checkbox']"));
//uncheck the checkbox
if(!checkbox.isSelected()) {
checkbox.click();
Util.pause("1000");
}