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.

2
  • 1
    Which Selenium Language Binding Art are you using? Java / Python / C# / NodeJS ? Your code trials? Commented Oct 11, 2018 at 5:31
  • I am using Selenium with Java Commented Oct 16, 2018 at 4:43

3 Answers 3

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"

Sign up to request clarification or add additional context in comments.

Comments

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();
      

1 Comment

I have already tried with isSelected() method. But unfortunately this method is not working for the above checkbox.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.