Reputation: 11
Selected Checkbox Webelement details:-
<label class="container_checkbox">
<input type="checkbox" class="Control Checkbox" value="on" style="display: inline-block;">
**<span class="checkmark">
::after
</span>**
</label>
Not-Selected Checkbox Webelement details:-
<label class="container_checkbox">
<input type="checkbox" class="Control Checkbox" value="on" style="display: inline-block;">
**<span class="checkmark"></span>**
</label>
To indicate the checkbox is selected the developer is using CSS ::after selector. How can I check whether the checkbox is selected or not using selenium webdriver.
Upvotes: 1
Views: 3327
Reputation: 193088
To validate if the checkbox is selected or not you can use the following solution:
Using isSelected()
method:
Java:
boolean selection = driver.findElement(By.xpath("//label[@class='container_checkbox']/input[@class='Control Checkbox']")).isSelected();
Upvotes: 1
Reputation: 2627
I hope you are familiar with c# syntax,
IWebElement ele = driver.FindElement(By.XPath("//label[@class='container_checkbox']/input[@class='Control Checkbox']"));
SelectElement select = new SelectElement(ele);
IList<IWebElement> allSelectedOp = select.AllSelectedOptions;
will gives you list of all selected options, if you want to be specific use below might help you,
Boolean IsSelected = driver.findElement(By.xpath("//label[@class='container_checkbox']/input[@class='Control Checkbox']")).isSelected();
you can verify Boolean value is True or False
Upvotes: 0
Reputation: 407
Try this out..
private boolean isChecked;
private WebElement e;
isChecked = e.findElement(By.tagName("input")).isSelected();
Or you can refer to this solution asked earlier
[Selenium checkbox attribute "checked"
Upvotes: 1