[英]How to click on multiple checkboxes in selenium webdriver?
I'm trying to check multiple Checkbox in a table via reading data from Excel
, it is actually able to read data from excel and locate the Checkbox but it does not check/click the checkbox. 我试图通过从Excel
读取数据来检查表中的多个Checkbox,实际上它能够从excel中读取数据并找到Checkbox,但它不检查/单击Checkbox。 The ongoingPrecuationsChk.click(); 正在进行的PrecuationsChk.click(); is not working and it does not show any exception(skips execution of the line), can somebody explain to me why it's not checking/clicking the checkbox? 无法正常工作,并且没有显示任何异常(跳过该行的执行),有人可以向我解释为什么它没有检查/单击复选框吗? Below is my html code: 以下是我的html代码:
<table id="ContentPlaceHolder1_ctl04_cbl_CCPOP01_01">
<tbody>
<tr>
<td>
<input id="ContentPlaceHolder1_ctl04_cbl_CCPOP01_01_0"
type="checkbox"
name="ctl00$ContentPlaceHolder1$ctl04$cbl_CCPOP01_01$0"
value=" Universal ">
<label for="ContentPlaceHolder1_ctl04_cbl_CCPOP01_01_0"> Universal </label></td>
<td><input id="ContentPlaceHolder1_ctl04_cbl_CCPOP01_01_1"
type="checkbox"
name="ctl00$ContentPlaceHolder1$ctl04$cbl_CCPOP01_01$1"
value=" Aspiration ">
<label for="ContentPlaceHolder1_ctl04_cbl_CCPOP01_01_1"> Aspiration </label></td>
<td><input id="ContentPlaceHolder1_ctl04_cbl_CCPOP01_01_2"
type="checkbox" name="ctl00$ContentPlaceHolder1$ctl04$cbl_CCPOP01_01$2"
value=" Respiratory ">
<label for="ContentPlaceHolder1_ctl04_cbl_CCPOP01_01_2"> Respiratory </label></td>
</tr>
</tbody>
I have tried the following code: 我尝试了以下代码:
String valueOngoingPrecuations = data.getOngoingPrecuations().get(rowCnt);//data reading from excel(Aspiration,Universal)
List<WebElement> ongoingPrecuations = driver.findElements(By.xpath("//input[@type='checkbox']"));
List<String> ongoingPrecuationsList = new ArrayList<String>(
Arrays.asList(valueOngoingPrecuations.split(",")));
for (String ongoingPrecuationsCheck : ongoingPrecuationsList) {
for (WebElement ongoingPrecuationsChk : ongoingPrecuations) {
if (ongoingPrecuationsChk.getAttribute("value").equalsIgnoreCase(ongoingPrecuationsCheck)) {
ongoingPrecuationsChk.click();
}
}
}
Use xpath based on id of tbody like below. 根据如下所示的tbody ID使用xpath。
//tbody[contains(@id,'tableBodyId')]//input
This will give you list of checkboxes. 这将为您提供复选框列表。 Then use 然后使用
WebElement btn = driver.findElement(By.xpath("xpath"));
btn.click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.