1

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

How can I implement that?

Michael Durrant
25.3k3 gold badges42 silver badges114 bronze badges
asked Feb 18, 2016 at 7:10

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();
}
answered Feb 18, 2016 at 7:23
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.

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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.