title: java.lang.ClassCastException: class org.openqa.selenium.By$ByXPath cannot be cast to class org.openqa.selenium.WebElement
body: <p>I am trying to automate radio button in selenium web driver using Page object model.
  Below is my code explanation:</p>
  
  <pre><code>By AutomaticDataLockTimed = By.xpath("//span[@class='ant-radio']//input[@name='automaticDataLock']");
  
  if (!((WebElement) AutomaticDataLockTimed).isSelected()) {
              JSUtil.clickElementUsingBySelector(AutomaticDataLockTimed, driver);
          }
      }
  </code></pre>
  
  <p>and I am getting below error message</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: class org.openqa.selenium.By$ByXPath cannot be 
    cast to class org.openqa.selenium.WebElement (org.openqa.selenium.By$ByXPath and org.openqa.selenium.WebElement are in unnamed module of loader 'app')</p>
  </blockquote>
  
  <p>I have referred this link <a href="https://stackoverflow.com/questions/48304961/java-lang-classcastexception-org-openqa-selenium-bybyid-cannot-be-cast-to-org">java.lang.ClassCastException: org.openqa.selenium.By$ById cannot be cast to org.openqa.selenium.WebElement</a> </p>
  
  <p>but this link did not answer my scenario.</p>
  
  <p>I think it is due to casting problem in my if statement but I cannot fix. </p>
  
  <p>Please help!</p>