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
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
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
-
1Why would you sleep for checking checkboxes?FDM– FDM2016年02月18日 07:23:41 +00:00Commented Feb 18, 2016 at 7:23
-
if there are multiple checkboxes, sync issue can happen right?Appu– Appu2016年02月18日 07:25:16 +00:00Commented Feb 18, 2016 at 7:25
-
For a simple case like this, Selenium has in my experience never failed without sleeping.FDM– FDM2016年02月18日 08:48:50 +00:00Commented Feb 18, 2016 at 8:48
-
hmm..okay. I just added it for extra safety. Maybe, I dont have enough experience like you.Appu– Appu2016年02月18日 09:40:20 +00:00Commented Feb 18, 2016 at 9:40
-
1adding sleep for "extra safety" without understanding why or what it does is en.wikipedia.org/wiki/Cargo_cult_programmingPeter M. - stands for Monica– Peter M. - stands for Monica2016年02月18日 14:42:33 +00:00Commented Feb 18, 2016 at 14:42
Explore related questions
See similar questions with these tags.
default