In my application, I have a grid with a column for check boxes. The ID of the check boxes for each row differs only by the number after a fixed value. xxxx_0, xxxx_1, ....
In order to select a check box in any row, the row number can be appended to get the complete ID.
My code is like this :
for(int i=0; i<10; i++) {
CheckBox visible = (CheckBox) driver.findElement(By.id("visibleCheckboxValue_" + i));
visible.toggle(false);
}
This gives me a run time error as "cannot cast Remote webdriver to CheckBox."
Also, if I use cast it as WebElement
, I cannot use the toggle(boolean select)
function.
for(int i=0; i<10; i++) {
WebElement visible = (WebElement) driver.findElement(By.id("visibleCheckboxValue_" + i));
if(visible.isSelected()) {
visible.click() // To uncheck the check box
}
}
On a WebElement
, I can use .isSelected()
to check if the check box is selected or not, but it always returns false. Even if the check box is selected, it returns false.
Is there any way to cast a Webdriver to CheckBox, so I can use the toggle()
function effectively ?