今天爲了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");
}