title: How to check state of a switch toggle in Selenium using c#
body: <p>I am trying to validate if a switch is 'on or 'off' using selenium but I cant seem to get it right. The toggle is set to the on position on loading the webpage but filter results in a table when it is off etc. It works fine i just check get my selenium tests to get its current state. </p>
  
  <ol>
  <li>element.Selected; always returns false (regards of toggle position) </li>
  <li>element.Enabled; always returns true (regards of toggle position) </li>
  <li>string test = myToggle.GetAttribute("class"); returns the text "slider round" which doesn't help  </li>
  <li>string test1 = myToggle.GetAttribute("checked"); is null</li>
  <li>string test2 = myToggle.GetAttribute("value"); is null</li>
  </ol>
  
  <p>Here is the code: </p>
  
  <pre><code>&lt;label class="switch"&gt;
  &lt;input type="checkbox" id="myToggle" checked /&gt;
  &lt;span class="slider round"&gt;&lt;/span&gt;
  &lt;/label&gt;
  </code></pre>
  
  <p>The code that checks the toggle position and loads the table data:</p>
  
  <pre><code>   if (Amt == currentAmt ) {
      if ($("#myToggle").prop("checked") == true) {
          loadMyProducts('NAN', $("#total").val());
      }
  </code></pre>
  
  <p>My test at the moment looks like this </p>
  
  <blockquote>
  <pre><code>    [FindsBy(How = How.XPath, Using = "//*[@id='divTestAcc']/div[1]/p[9]/label/span")]
    public IWebElement myToggle { get; set; }
  
      public Boolean CheckMyToogleIsOnorOFF()
      {
          string test = myToggle.GetAttribute("class");
          Console.Write("checking "+ test);
  
          // string test1 = myToggle.GetAttribute("checked");
          //string test2 = myToggle.GetProperty("checked");
          // .Selected always returns false
          // .Enables always returns true 
  
          Boolean result;
          result = myToggle.Enabled;
          bool result1 = myToggle.Selected;
  
          if (result == true)
          {
              Console.WriteLine("My toggle is enabled");
          }
          else
          {
              Console.WriteLine("My toggle is not enabled");
          }
          return result;
      }
  </code></pre>
  </blockquote>