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");            
  }

 

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