1

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

1

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"

Rao
  • 397
  • 1
  • 12
1

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();
      
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

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

Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29