Unable to Check or Uncheck the check box

4,168 views
Skip to first unread message

Naresh

unread,
Jun 1, 2012, 12:13:33 PM6/1/12
to seleniu...@googlegroups.com
Hello all,

I am trying to Check or Uncheck a checkbox using selenium. But it's not working.

Here is my HTML.

<div class="toggle-slide-button">
    <label for="privacy-mode">
        <span>Privacy mode</span>
        <span class="toggler off">
            <span class="text">Off</span>
            <span class="handle">
                <input checked="checked" data-offtitle="Off" data-ontitle="On" id="PrivacyMode" name="PrivacyMode" title="Off" type="checkbox" value="true" /><input name="PrivacyMode" type="hidden" value="false" />
            </span>
            <span class="glow"></span>
        </span>
    </label>
</div>


I have tried using selenium.WebDriverBackedSelenium.Check("PrivacyMode"), selenium.WebDriverBackedSelenium.Uncheck("PrivacyMode").

I tried IWebElement.Click() also, but none of them working.

But selenium.WebDriverBackedSelenium.IsChecked("PrivacyMode") retuning correct value based on checkbox chek or uncheck.

Please help me.

Thanks.

Mike Riley

unread,
Jun 1, 2012, 1:43:44 PM6/1/12
to seleniu...@googlegroups.com
Okay...  I am guessing you are not using Java, since your capitalization is all wrong and you would just use selenium.checked() where selenium is declared as WebDriverBackedSelenium.

Using the Java versions and WebDriverBackedSelenium I am having no problems with check() and uncheck().

So whatever language binding you are using seems to be at fault here.

Mike

Naresh Thandu

unread,
Jun 1, 2012, 1:53:00 PM6/1/12
to seleniu...@googlegroups.com
Hello Mike,

Thanks for responding.

I am using C# as my programming language. If you are using Java API's, I think syntax would be different from C#.

I am able to get the result whem I am using selenium.WebDriverBackedSelenium.IsChecked (could be selenium.checked()  in Java).

But I am not able to Check or Uncheck the check box.

Thanks,
Naresh

On Fri, Jun 1, 2012 at 6:43 PM, Mike Riley <lvsk...@cox.net> wrote:
Okay...  I am guessing you are not using Java, since your capitalization is all wrong and you would just use selenium.checked() where selenium is declared as .


Using the Java versions and WebDriverBackedSelenium I am having no problems with check() and uncheck().

So whatever language binding you are using seems to be at fault here.

Mike


On Friday, June 1, 2012 9:13:33 AM UTC-7, Naresh wrote:
Hello all,

I am trying to Check or Uncheck a checkbox using selenium. But it's not working.

Here is my HTML.

<div class="toggle-slide-button">
    <label for="privacy-mode">
        <span>Privacy mode</span>
        <span class="toggler off">
            <span class="text">Off</span>
            <span class="handle">
                <input checked="checked" data-offtitle="Off" data-ontitle="On" id="PrivacyMode" name="PrivacyMode" title="Off" type="checkbox" value="true" /><input name="PrivacyMode" type="hidden" value="false" />
            </span>
            <span class="glow"></span>
        </span>
    </label>
</div>


I have tried using selenium.WebDriverBackedSelenium.Check("PrivacyMode"), selenium.WebDriverBackedSelenium.Uncheck("PrivacyMode").

I tried IWebElement.Click() also, but none of them working.

But selenium.WebDriverBackedSelenium.IsChecked("PrivacyMode") retuning correct value based on checkbox chek or uncheck.

Please help me.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/vPR64XRKNIQJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.



--
Regards,
Naresh Thandu,
+91-9916710222

Moises Siles

unread,
Jun 1, 2012, 2:06:54 PM6/1/12
to seleniu...@googlegroups.com
I'm using part of this code to check my Checkboxes


                if (!webElement.GetAttribute("type").ToLower().Equals("checkbox"))

                {

                    throw new Exception("This elementLocator is not a checkbox!");

                }

 

                if (!webElement.Selected)

                {

                    Click(webElement);

Naresh Thandu

unread,
Jun 1, 2012, 2:39:10 PM6/1/12
to seleniu...@googlegroups.com
I have tried

IWebElement's click which could be like

webelement.Click();

As well as I have tried, selenium.WebDriverBackedSelenium.Click("id").

But no result.

In your code, you are calling 'Click', which method it would be calling internally?

Thanks,
Naresh

Moises Siles

unread,
Jun 1, 2012, 3:02:32 PM6/1/12
to seleniu...@googlegroups.com
it is webdriver.click

could you show us your html?

Naresh Thandu

unread,
Jun 1, 2012, 3:03:28 PM6/1/12
to seleniu...@googlegroups.com
<div class="toggle-slide-button">
    <label for="privacy-mode">
        <span>Privacy mode</span>
        <span class="toggler off">
            <span class="text">Off</span>
            <span class="handle">
                <input checked="checked" data-offtitle="Off" data-ontitle="On" id="PrivacyMode" name="PrivacyMode" title="Off" type="checkbox" value="true" /><input name="PrivacyMode" type="hidden" value="false" />
            </span>
            <span class="glow"></span>
        </span>
    </label>
</div>


Hien Ngo

unread,
Jun 1, 2012, 3:56:39 PM6/1/12
to seleniu...@googlegroups.com
Try this to see if this clicks checked:
((IJavaScriptExecutor)driver).ExecuteScript("document.getElementById('PrivacyMode').checked=true");
 
Lerry

Naresh Thandu

unread,
Jun 2, 2012, 6:50:05 AM6/2/12
to seleniu...@googlegroups.com
Hello Hien,

Script executor is returning null.

Please see the below code.

scriptExecutor.ExecuteScript("document.getElementById('PrivacyMode').checked=false");
null
scriptExecutor.ExecuteScript("document.getElementById('PrivacyMode').checked=true");
null
scriptExecutor.ExecuteScript("document.getElementById('PrivacyMode')");
null

Above code was from my immediate window. 

Thanks

Hien Ngo

unread,
Jun 4, 2012, 10:51:22 AM6/4/12
to seleniu...@googlegroups.com
I forgot the semicolon:
scriptExecutor.ExecuteScript("document.getElementById('PrivacyMode').checked=false;");

Naresh

unread,
Jun 6, 2012, 4:02:41 AM6/6/12
to seleniu...@googlegroups.com
Hello Lerry,

Still no luck........:(

It's not working with semicolon also ...

Thanks,
Naresh

Maxim Vorobev

unread,
Jun 6, 2012, 5:22:55 AM6/6/12
to seleniu...@googlegroups.com
Try to click on <span> node instead of <input>:
xpath=//span[@class='handle' and ./input[@id='PrivacyMode']]

2012/6/6 Naresh <naresh...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/CfsFqnS2WMgJ.

Naresh

unread,
Jun 6, 2012, 5:48:47 AM6/6/12
to seleniu...@googlegroups.com
Thanks Maxim.

Click on <span> is working.

Thank you so much.....

But why this Check() and Uncheck() are not working. Any idea on this?

Thanks,
Naresh

Naresh

unread,
Jun 6, 2012, 8:17:53 AM6/6/12
to seleniu...@googlegroups.com
Hello all,

Apart from click on <span>, WebDriver.Type("locator",""value") is also working.

Thanks,
Naresh

Shiva Santosh

unread,
Apr 27, 2015, 1:22:07 AM4/27/15
to seleniu...@googlegroups.com
Hi All,

I am unable to select Check box in a webpage using selenium web driver.
My HTML would be like <label for="caseIndividual0">.
Below code is not working. Even though i am not getting any exception, checkbox is not getting selected.

WebElement abc35 = oWebDriver.findElement(By.cssSelector("label[for=caseIndividual0]"));
System.out.println(abc35.isDisplayed()); - is returning true.
but abc35.click() is not working.

Shawn Conlin

unread,
Apr 30, 2015, 2:55:01 AM4/30/15
to seleniu...@googlegroups.com
You are selecting the label rather than the actual control. From the code you posted, you should be looking for an <Input> with type=checkbox and either the name or id of caseIndividual0. You might get lucky and be able to use By.id("caseIndividual0") for the locator in your findElement.

Madan Singh

unread,
Apr 30, 2015, 4:59:26 AM4/30/15
to seleniu...@googlegroups.com
Hi Naresh,

would you like to try this,

IWebElement checkelement = driver.FindElements(By.CssSelector("div>label>span>span>input[type='checkbox']"))[0];

checkelement.Click();

this is in C#

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.



--
M P Singh
9971360313

Suba

unread,
Feb 12, 2016, 1:11:03 AM2/12/16
to Selenium Users
Hi Shiva,

Are you able to fix this problem? if so, can you please tell me how did you resolve it? 
My html code is like this :
<div class="six wide tablet three wide computer-minor column">
<div class="field">
<label class="tablet computer only"/>
<div class="ui checkbox inline-form-element">
<input id="so" class="ng-pristine ng-untouched ng-valid" type="checkbox" data-ng-model="filters.so"/>
<label for="so">Special offers only!</label>
</div>
</div>
</div>

I am unable to check the checkbox.. Please suggest.

Cheers,
Suba

saba. s

unread,
Feb 12, 2016, 4:45:07 AM2/12/16
to seleniu...@googlegroups.com
Hi suba,

Make use of this,

driver.findElement(By.id("so")).click();

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--







Thanks,
Kanaga sabapathy.M.S.
Reply all
Reply to author
Forward
0 new messages