Selenium:如何利用webdriver uncheck checkbox

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章