title: Checking and unchecking of a checkbox using Selenium WebDriver
body: <p>Checking and unchecking of a checkbox using Selenium WebDriver.</p>
  <p>I am using the <a href="https://www.automatetheplanet.com/page-object-pattern/" rel="nofollow noreferrer">page object pattern</a>, so my code appears this way.</p>
  <pre><code>SelectCheckBox(&quot;Check&quot;);  OR  SelectCheckBox(&quot;Uncheck&quot;);
  
  [FindsBy(How = How.Id, Using = &quot;payment_sameasdeliveryaddress&quot;)]
  public IWebElement checkbox_Address = null;
  
  public void SetCheckBox(string value)
  {
      //Console.Write(&quot;checkbox state: &quot; + checkbox_Address.Selected);
      if (value.ToLower().Equals(&quot;uncheck&quot;) &amp;&amp; checkbox_Address.Selected)
      {
          checkbox_Address.Click();
      }
      else if (value.ToLower().Equals(&quot;check&quot;) &amp;&amp; !checkbox_Address.Selected)
      {
          checkbox_Address.Click();
      }
  </code></pre>