I have a method:
public void clickCheckBox(int index) {
List<WebElement> sizeList = getSizeList();
WebElement checkbox = sizeList.get(index);
Actions action = new Actions(driver);
action.moveToElement(checkbox).click().build().perform();
}
This method is taking the index of a list of checkboxes and then using Actions class to check the checkbox. I am doing it this way because the page I am currently working with triggers an event when this checkbox is checked so just doing a simple find the checkbox and click doesn't work (event doesn't fire).
My above code is not checking the checkbox and I'm not sure why. Any insight would be great. Please let me know if I didn't provide enough information.
EDIT:
Here is my method getting the size of the list:
public List<WebElement> getSizeList(){
List<WebElement> sizeList = body.findElement(By.cssSelector("ul")).findElements(By.cssSelector("li"));
if(null==sizeList) {
// oops, couldn't find the element
LOGGER.error("Failed to locate the 'li' element for the action button");
return Collections.emptyList();
}
return sizeList;
}
Here is a bit of the HTML:
<ul>
<li>
<input type="checkbox">
<a href="www.url.com" title="8">8</a>
<span class="count">(1,037)</span>
</li>
<li>
<input type="checkbox">
<a href="www.url.com" title="10">10</a>
<span class="count">(1,047)</span>
</li> ...