As there are five number of check boxes in a page, i have selected two check boxes. so i want to get the number of size as two check box selected. How to get the number of size as two in selenium web-driver?
Note: List<WebElement> boxes = driver.findElements(By.name("vehicle")).click();
System.out.println(boxes.size()
+ "Number of check boxes present in the page");
it gives me the entire number of check boxes, As the above scenario is not needed.
-
It is not clear to me what you are trying to do here. You are both getting a list of the elements with that name and clicking on them?Dan Snell– Dan Snell2014年04月04日 16:20:44 +00:00Commented Apr 4, 2014 at 16:20
-
@Emmanuel Angelo- I used PoulDonny code in my TEST APPLICATION and was working fine. It is working as you mentioned in your scenario :). I was selected 2 check-boxes and O/P: 2 Number of check boxe is selected in the page. Please check your query and discussions?. YOU NEED TO POST CRISTAL CLEAR QUERY..QA4it– QA4it2014年04月04日 17:06:51 +00:00Commented Apr 4, 2014 at 17:06
2 Answers 2
driver.findElements(By.name("vehicle").click();
int i = 0;
for (WebElement we:driver.findElements(By.name("vehicle")) {
if (we.isSelected()) { i++; }
}
System.out.println(i
+ " Number of check boxes present in the page");
That should give no issues. But you are looping through an entire list to always come to the same answer, 1.
-
as there are three check-boxes in the web page, i have clicked only one box. so at this point i should the get the system.out.println as '1 check box selected'. All the check-box have the same element name 'vehicle'.Emmanuel Angelo.R– Emmanuel Angelo.R2014年04月04日 13:33:47 +00:00Commented Apr 4, 2014 at 13:33
-
So you are only attempting to click one of them randomly?Paul Muir– Paul Muir2014年04月04日 13:35:14 +00:00Commented Apr 4, 2014 at 13:35
-
yes you're correct im clicking one at randomEmmanuel Angelo.R– Emmanuel Angelo.R2014年04月04日 13:36:43 +00:00Commented Apr 4, 2014 at 13:36
I'm no wizard when it comes to actually coding this, but I used to inject variables with JS into Selenium IDE (back in the day) that would collect certain actions a they were performed. Perhaps you can use the action for clicking the checkbox to increase a simple count variable to use in your script above?