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

How can I implement that?

2 Answers 2


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!
List <webelement> checkboxele= driver.findelements(By..whatever property you wish, id or xpath")
for(webelement ele:checkboxele){

//Thread.sleep(1000); depends

This will click on all checkboxes in your page.

  • 1
    Why would you sleep for checking checkboxes?
    – FDM
    Commented Feb 18, 2016 at 7:23
  • if there are multiple checkboxes, sync issue can happen right?
    – Appu
    Commented Feb 18, 2016 at 7:25
  • For a simple case like this, Selenium has in my experience never failed without sleeping.
    – FDM
    Commented Feb 18, 2016 at 8:48
  • hmm..okay. I just added it for extra safety. Maybe, I dont have enough experience like you.
    – Appu
    Commented 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 Commented 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.