Need Help - How to Uncheck a checkbox in web driver with java

9,009 views
Skip to first unread message

mo

unread,
Nov 16, 2011, 9:58:18 PM11/16/11
to Selenium Users
Hi All,
I use web driver with java. I have a checkbox in a page that is
selected by default. How can I un-check it? Please help

-Mo

saran kumar

unread,
Nov 17, 2011, 10:07:47 PM11/17/11
to seleniu...@googlegroups.com
Hi Mohammed,
 
As you Said, the check box already checked in your page.
 
so when ever that page loads, your test case should find the check box element and all you have to do is another check in the check box. so it will uncheck the check box.
(i.e) in your test case try with this command...
selenium.click("ID of the checkbox") -- if its static
or
selenium.click ("NAME of the checkbox")--if its dynamic
 
Try it ..this might work
 
Thanks
Saran


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
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.


Mike

unread,
Nov 18, 2011, 2:24:35 PM11/18/11
to Selenium Users
He is using WebDriver, not Selenium. Having said that, I also use
WebDriver, but have WebDriverBackedSelenium set up so I can use
Selenium methods when it is convenient. With Selenium you can do
selenium.uncheck("locator") to uncheck it or selenium.check("locator")
to check it, without knowing the current state. You can check the
state using selenium.isChecked("locator").

Mike

mohammed shahriar

unread,
Nov 18, 2011, 3:12:28 PM11/18/11
to seleniu...@googlegroups.com
Thanks both Mike & Saran,
I imported "org.openqa.selenium.WebDriverBackedSelenium"  to my WebDriver java code as Mike mentioned and used selenium.click("name of checkbox") to uncheck the checkbox selection. Job done as expected

Thanks again guys
-mo

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
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.




--
Thanks
-Mohammed Shahriar
707-479-7587

Mark Collin

unread,
Nov 18, 2011, 6:21:44 PM11/18/11
to seleniu...@googlegroups.com

I would suggest the following as a WebDriver implementation:

 

public void check(By locator) throws Exception{

   WebElement checkBox = driver.findElement(locator);

   if(!checkBox.getAttribute("type").toLowerCase().equals("checkbox")){

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

    }

    if(checkBox.isSelected()){

        checkBox.click();

    }

}

   

public void uncheck(By locator) throws Exception{

    WebElement checkBox = driver.findElement(locator);

    if(!checkBox.getAttribute("type").toLowerCase().equals("checkbox")){

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

    }

    if(!checkBox.isSelected()){

        checkBox.click();


-- This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error please notify postm...@ardescosolutions.com

Lutfi Dughman

unread,
Nov 18, 2011, 6:47:22 PM11/18/11
to seleniu...@googlegroups.com
the negation should be in the check() not the uncheck method, in the check method if the checkbox is selected there is no need to click it.

 if(checkBox.isSelected()){

        checkBox.click();

Lutfi Dughman

unread,
Nov 18, 2011, 8:16:58 PM11/18/11
to seleniu...@googlegroups.com
Also you can replace toLowerCase().equals with equalsIgnoreCase() method

Mark Collin

unread,
Nov 19, 2011, 3:47:14 AM11/19/11
to seleniu...@googlegroups.com

Doh J  Teach me to do stuff late at night.

Dhanraj

unread,
Dec 2, 2011, 8:06:16 AM12/2/11
to seleniu...@googlegroups.com
Hi All,

I have 2 buttons with same name . How to check whether its checked or unchecked.
I want to check only if its unchecked.
 
HTML snippet:

<input type="radio" onclick="cf(this)" name="dashboard_TSS_querygroup_TSS_refresh" value="true"> True&nbsp;&nbsp;<input type="radio" checked="" onclick="cf(this)" name="dashboard_TSS_querygroup_TSS_refresh" value="false">False</td>

I am using WebDriver with Java.

Regards,
Dhanaraja.

Mike

unread,
Dec 2, 2011, 5:37:37 PM12/2/11
to Selenium Users
They have the same name to make them exclusive to each other. Have
your developer add a unique ID to each one and you can address them
that way. The other option, if the HTML can't be changed, would be to
use XPath with a subscript [1] and [2].

Mike

On Dec 2, 5:06 am, Dhanraj <dhanuu...@gmail.com> wrote:
> Hi All,
>
> I have 2 buttons with same name . How to check whether its checked or
> unchecked.
> I want to check only if its unchecked.
>
> HTML snippet:
>
> <input type="radio" onclick="cf(this)"
> name="dashboard_TSS_querygroup_TSS_refresh" value="true">
> True&nbsp;&nbsp;<input type="radio" checked="" onclick="cf(this)"
> name="dashboard_TSS_querygroup_TSS_refresh" value="false">False</td>
>
> I am using WebDriver with Java.
>
> Regards,
> Dhanaraja.
>

> On Sat, Nov 19, 2011 at 2:17 PM, Mark Collin <m...@ardescosolutions.com>wrote:
>
>
>
>
>
>
>
> > Doh J  Teach me to do stuff late at night.****
>
> > ** **
>
> > *From:* seleniu...@googlegroups.com [mailto:
> > seleniu...@googlegroups.com] *On Behalf Of *Lutfi Dughman
> > *Sent:* 18 November 2011 23:47
>
> > *To:* seleniu...@googlegroups.com
> > *Subject:* Re: [selenium-users] Re: Need Help - How to Uncheck a checkbox
> > in web driver with java****
>
> > ** **


>
> > the negation should be in the check() not the uncheck method, in the check

> > method if the checkbox is selected there is no need to click it.****
>
> > ** **
>
> >  if(checkBox.isSelected()){****
>
> >         checkBox.click();****
>
> >     }****
>
> > ** **
>
> > On Fri, Nov 18, 2011 at 6:21 PM, Mark Collin <m...@ardescosolutions.com>
> > wrote:****
>
> > I would suggest the following as a WebDriver implementation:****
>
> >  ****
>
> > public void check(By locator) throws Exception{****
>
> >    WebElement checkBox = driver.findElement(locator);****
>
> >    if(!checkBox.getAttribute("type").toLowerCase().equals("checkbox")){***
> > *
>
> >         throw new Exception("This element is not a checkbox!");****
>
> >     }****
>
> >     if(checkBox.isSelected()){****
>
> >         checkBox.click();****
>
> >     }****
>
> > }****
>
> >     ****
>
> > public void uncheck(By locator) throws Exception{****
>
> >     WebElement checkBox = driver.findElement(locator);****
>
> >     if(!checkBox.getAttribute("type").toLowerCase().equals("checkbox")){**
> > **
>
> >         throw new Exception("This element is not a checkbox!");****
>
> >     }****
>
> >     if(!checkBox.isSelected()){****
>
> >         checkBox.click();****
>
> >     }****
>
> > }****
>
> >  ****
>
> > *From:* seleniu...@googlegroups.com [mailto:
> > seleniu...@googlegroups.com] *On Behalf Of *mohammed shahriar
> > *Sent:* 18 November 2011 20:12
> > *To:* seleniu...@googlegroups.com
> > *Subject:* Re: [selenium-users] Re: Need Help - How to Uncheck a checkbox
> > in web driver with java****
>
> >  ****
>
> > Thanks both Mike & Saran,****


>
> > I imported "org.openqa.selenium.WebDriverBackedSelenium"  to my WebDriver
> > java code as Mike mentioned and used selenium.click("name of checkbox") to

> > uncheck the checkbox selection. Job done as expected****
>
> >  ****
>
> > Thanks again guys****
>
> > -mo****
>
> >  ****
>
> > On Fri, Nov 18, 2011 at 11:24 AM, Mike <lvskip...@cox.net> wrote:****


>
> > He is using WebDriver, not Selenium.  Having said that, I also use
> > WebDriver, but have WebDriverBackedSelenium set up so I can use
> > Selenium methods when it is convenient.  With Selenium you can do
> > selenium.uncheck("locator") to uncheck it or selenium.check("locator")
> > to check it, without knowing the current state.  You can check the
> > state using selenium.isChecked("locator").
>

> > Mike****


>
> > On Nov 17, 7:07 pm, saran kumar <saran...@gmail.com> wrote:
> > > Hi Mohammed,
>
> > > As you Said, the check box already checked in your page.
>
> > > so when ever that page loads, your test case should find the check box
> > > element and all you have to do is another check in the check box. so it
> > > will uncheck the check box.
> > > (i.e) in your test case try with this command...
> > > selenium.click("ID of the checkbox") -- if its static
> > > or
> > > selenium.click ("NAME of the checkbox")--if its dynamic
>
> > > Try it ..this might work
>
> > > Thanks
> > > Saran
>

> > >****


>
> > > On Thu, Nov 17, 2011 at 8:28 AM, mo <mohammed.shahr...@gmail.com> wrote:
> > > > Hi All,
> > > > I use web driver with java. I have a checkbox in a page that is
> > > > selected by default. How can I un-check it? Please help
>
> > > > -Mo
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Selenium Users" group.
> > 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.****
>
> > ****
>
> >  ****
>
> > --
> > Thanks
> > -Mohammed Shahriar
> > 707-479-7587****


>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Selenium Users" group.
> > 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.****


>
> > -- This message contains confidential information and is intended only for
> > the individual named. If you are not the named addressee you should not
> > disseminate, distribute or copy this e-mail. Please notify the sender
> > immediately by e-mail if you have received this e-mail by mistake and
> > delete this e-mail from your system. If you are not the intended recipient
> > you are notified that disclosing, copying, distributing or taking any
> > action in reliance on the contents of this information is strictly
> > prohibited. If you have received this email in error please notify

> > postmas...@ardescosolutions.com ****


>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Selenium Users" group.
> > 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.****
>
> > ** **


>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Selenium Users" group.
> > 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.****


>
> > -- This message contains confidential information and is intended only for
> > the individual named. If you are not the named addressee you should not
> > disseminate, distribute or copy this e-mail. Please notify the sender
> > immediately by e-mail if you have received this e-mail by mistake and
> > delete this e-mail from your system. If you are not the intended recipient
> > you are notified that disclosing, copying, distributing or taking any
> > action in reliance on the contents of this information is strictly
> > prohibited. If you have received this email in error please notify

> > postmas...@ardescosolutions.com

Nishanth Nanchari

unread,
Oct 27, 2018, 11:26:56 PM10/27/18
to Selenium Users

Screenshot_2018-10-27 actiTIME - User List.png

Hello All,


can anyone help me to uncheck these checked check boxes using java


html clode of  checkbox:

<img src="/img/default/check.gif" title="Click to revoke <%= rightDescription %> access right" alt="Click to revoke <%= rightDescription %> access right" width="14" height="13">

Reply all
Reply to author
Forward
0 new messages