Can Selenium evaluate all XPath elements?
selenium, xpath
Solution
You can use the getXpathCount command to determine the number of matching elements. You can then loop through them using an increment to locate each element individually. The following Java (TestNG/JUnit) example would check that all checkboxes on a page are checked:
int totalCheckboxes = session().getXpathCount("//input[@type='checkbox']").intValue();
for (int i = 1; i < totalCheckboxes+1; i++) {
assertTrue(session().isChecked("//input[@type='checkbox'][" + i + "]"));
}
Problem
Is it possible for Selenium to evaluate all the elements that may match a certain `XPath`? For instance, I'd like to evaluate whether all checkboxes are checked with `//input[type='checkbox']`--problem is I only get one element returned.