As i want to click the multiple checkboxes in selenium webdriver, so that im using the ‘id’ webelement to click but what problem i’m facing means all the checkboxes id’s are same in my HTML so is there anyway to click multiple checkboxes?
Here im posting my HTML code: first check box:
<tbody role="rowgroup"> <tr data-uid="6adb7eb4-7169-4ab8-aef4-cc8b2774beac" role="row" class="k-state-selected" aria-selected="true"><td style="text-align:left" role="gridcell">Order</td><td style="text-align:left" role="gridcell">55</td><td style="text-align:left" role="gridcell">ORD55</td><td style="text-align:right" role="gridcell">2,400.00</td><td style="text-align:right" role="gridcell">2,400.00</td><td style="text-align:center" role="gridcell" id="GridPayRecp_active_cell" class="" aria-describedby="c7c68ce1-edc3-4958-a6c1-2611999356b0 GridPayRecp_active_cell"><input type="checkBox" id="chkSelect" onclick="EditchkSelect()" height="15px;" width="15px;" checked=""></td><td style="text-align:right" role="gridcell">2,400.00</td></tr><tr class="k-alt" data-uid="3f3d1588-6f42-4c22-bdda-28c090ece58b" role="row"><td style="text-align:left" role="gridcell">Order</td><td style="text-align:left" role="gridcell">57</td><td style="text-align:left" role="gridcell">ORD57</td><td style="text-align:right" role="gridcell">3,600.00</td><td style="text-align:right" role="gridcell">3,597.00</td><td style="text-align:center" role="gridcell"><input type="checkBox" id="chkSelect" onclick="EditchkSelect()" height="15px;" width="15px;"></td><td style="text-align:right" role="gridcell">0.00</td></tr><tr data-uid="1ab110de-fbe6-4954-b612-39c3cb7fc8ba" role="row"><td style="text-align:left" role="gridcell">Proforma</td><td style="text-align:left" role="gridcell">90</td><td style="text-align:left" role="gridcell">PRO90</td><td style="text-align:right" role="gridcell">3,600.00</td><td style="text-align:right" role="gridcell">3,366.00</td><td style="text-align:center" role="gridcell"><input type="checkBox" id="chkSelect" onclick="EditchkSelect()" height="15px;" width="15px;"></td><td style="text-align:right" role="gridcell">0.00</td></tr> </tbody>
second checkbox:
<tbody role="rowgroup"> <tr data-uid="6adb7eb4-7169-4ab8-aef4-cc8b2774beac" role="row" class="k-state-selected" aria-selected="true"><td style="text-align:left" role="gridcell">Order</td><td style="text-align:left" role="gridcell">55</td><td style="text-align:left" role="gridcell">ORD55</td><td style="text-align:right" role="gridcell">2,400.00</td><td style="text-align:right" role="gridcell">2,400.00</td><td style="text-align:center" role="gridcell" id="GridPayRecp_active_cell" class="" aria-describedby="c7c68ce1-edc3-4958-a6c1-2611999356b0 GridPayRecp_active_cell"><input type="checkBox" id="chkSelect" onclick="EditchkSelect()" height="15px;" width="15px;" checked=""></td><td style="text-align:right" role="gridcell">2,400.00</td></tr><tr class="k-alt" data-uid="3f3d1588-6f42-4c22-bdda-28c090ece58b" role="row"><td style="text-align:left" role="gridcell">Order</td><td style="text-align:left" role="gridcell">57</td><td style="text-align:left" role="gridcell">ORD57</td><td style="text-align:right" role="gridcell">3,600.00</td><td style="text-align:right" role="gridcell">3,597.00</td><td style="text-align:center" role="gridcell"><input type="checkBox" id="chkSelect" onclick="EditchkSelect()" height="15px;" width="15px;"></td><td style="text-align:right" role="gridcell">0.00</td></tr><tr data-uid="1ab110de-fbe6-4954-b612-39c3cb7fc8ba" role="row"><td style="text-align:left" role="gridcell">Proforma</td><td style="text-align:left" role="gridcell">90</td><td style="text-align:left" role="gridcell">PRO90</td><td style="text-align:right" role="gridcell">3,600.00</td><td style="text-align:right" role="gridcell">3,366.00</td><td style="text-align:center" role="gridcell"><input type="checkBox" id="chkSelect" onclick="EditchkSelect()" height="15px;" width="15px;"></td><td style="text-align:right" role="gridcell">0.00</td></tr></tbody>
third checkbox:
</tbody>
Advertisement
Answer
How to click on all checkboxes with the same ID, (Java example):
WebDriverWait wait = new WebDriverWait(driver, 10); List<WebElement> checkboxes = wait.until(ExpectedConditions .presenceOfAllElementsLocatedBy(By.cssSelector("tr[role=row] input#chkSelect[type=checkBox]"))); for (WebElement checkbox : checkboxes) { wait.until(ExpectedConditions.elementToBeClickable(checkbox)).click(); }
Click first and second checkboxes for each row:
WebDriverWait wait = new WebDriverWait(driver, 10); List<WebElement> rows = wait.until(ExpectedConditions .presenceOfAllElementsLocatedBy(By.cssSelector("tr[role=row]"))); for (WebElement row : rows) { List<WebElement> checkboxes = driver.findElements(By.cssSelector("input#chkSelect[type=checkBox]")); wait.until(ExpectedConditions.elementToBeClickable(checkboxes.get(0))).click(); wait.until(ExpectedConditions.elementToBeClickable(checkboxes.get(1))).click(); }