1

I want to mark all the checkboxes in a page using selenium webdriver?

How can I implement that?

2 Answers 2

1

First, assign all checkbox elements to a list.

List<WebElement> list = driver.findElements(By.Xpath("//input[type='checkbox']"));

Then, loop through the list, for example

for(WebElement el : list){
    if(!el.isChecked()) // validate Checked property, otherwise you'll uncheck!
        el.click();
}
0
List <webelement> checkboxele= driver.findelements(By..whatever property you wish, id or xpath")
for(webelement ele:checkboxele){

ele.click();
//Thread.sleep(1000); depends
}

This will click on all checkboxes in your page.

5
  • 1
    Why would you sleep for checking checkboxes?
    – FDM
    Feb 18, 2016 at 7:23
  • if there are multiple checkboxes, sync issue can happen right?
    – Appu
    Feb 18, 2016 at 7:25
  • For a simple case like this, Selenium has in my experience never failed without sleeping.
    – FDM
    Feb 18, 2016 at 8:48
  • hmm..okay. I just added it for extra safety. Maybe, I dont have enough experience like you.
    – Appu
    Feb 18, 2016 at 9:40
  • 1
    adding sleep for "extra safety" without understanding why or what it does is en.wikipedia.org/wiki/Cargo_cult_programming Feb 18, 2016 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.