First, I want to check whether checkbox is selected or not and then have to perform select action. But here isselected method always giving false output, because the script is selecting the checkbox if it is not selected and deselecting if it is selected.

<div class="wrapper-tagline primary checkbox check-success">
<input id="checkbox" type="checkbox" checked="" value="1">
<label class="main-title section-option" for="checkbox">
<span>Show Section</span>
<div class="section-option-wrapper">

Any suggested solution?

  • 2
    Can you please add a snippet of your code and potentially the piece of HTML that you are attempting to work with.
    – Paul Muir
    Oct 7, 2015 at 13:12
  • 1
    you should give the snippet of code, which will help use determine what is wrong. Oct 7, 2015 at 15:16
  • Depending on how the html is coded, you need to provide us with that same HTML with the item checked and when it is unchecked. I am assuming that in the input tag checked is an empty string when unselected and a value of 1 when selected. Please tell me if it's checked in your above code.
    – DEnumber50
    Oct 8, 2015 at 21:47

4 Answers 4


I too faced the same problem. In my case I observed that the class name was changing on selecting/de-selecting the check box.For example the checkbox element when de-selected appears somewhat like this:

<input class="checkbox" id="current_year" name="current_year" type="checkbox" value="true">

and when it is checked/selected it appears lke this:

<input class="checkbox checked" id="current_year" name="current_year" type="checkbox" value="true">

I therefore used the class attribute in my xpath to determine if the checkbox is selected or not. For example to check if the checkbox is selected I used:

driver.findElement(By.xpath("//*[@id='current_year' and @class='checkbox checked']")).isDisplayed();

and to check if the checkbox is not selected I used:

driver.findElement(By.xpath("//*[@id='current_year' and @class='checkbox']")).isDisplayed();

You can check if any attribute in the checkbox element is changing on selecting it and can use the same to check if the checkbox is selected or not.

 boolean v=driver.findElement(By.xpath("//input[@type='checkbox']")).isSelected( );

Try the above code.

  • 4
    While this is certainly the way to use the above method, but we don't know why the OP is getting the false every time. Simply mentioning a one line code is not going to solve until you know why the code failed at the first place. Oct 12, 2015 at 6:18

From the question I gues your syntax might by the problem. Instead of isselected() you must use isSelected() (S in selected is in uppercase).

You can also try using an alternative, for example, isChecked() or isActive() method instead of isSelected(). See if that works for you.

Try something like

boolean v=driver.findElement(By.xpath("the xpath here")).isChecked( );


According to my experience, I see for a checkbox isselected() works only on certain DOM. For the other cases, it just returns "False".

In your case DOM is

It's having attribute "checked". This will have different values for checked and Unchecked status. You can use this attribute to verify status of the checkbox.

sample code: WebElement checkbox=driver.findElement(By.id("checkbox"));
String checkboxStatus=checkbox.getattribute("checked");

Now based checked attribute value, you can perform your action on checkbox

If you are not clear go through https://youtu.be/c6a7tAoKIo0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.