title: Selecting Radio Buttons based on User Input in Selenium Webdriver
body: <p>I want to be able to select a radio button based on User input. This radio button has multiple options with the same name. </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;th class="radio"&gt;
   &lt;td&gt;
    &lt;label for="form-1-input-3"&gt;
     &lt;input id="form-1-input-3" type="radio" checked="" value="true" name="enabled"&gt;
     Enabled  
    &lt;/label&gt;
    &lt;label for="form-1-input-4"&gt;
     &lt;input id="form-1-input-4" type="radio" value="false" name="enabled"&gt;
     Disabled  
    &lt;/label&gt;
  </code></pre>
  
  <p>If "enabled" is passed as a string, I should be able to select the first radio button that has the visible text, Enabled and if "disabled" is passed as a string, I should be able to select radio button that has visible text, Disabled.</p>
  
  <p>I am having difficulty since the name of the radio button is same. The below code fails to find the element with the AND operator for Xpath. Has anyone encountered this before and have found a solution?</p>
  
  <pre class="lang-java prettyprint-override"><code>String enableRadioButtonXPath = "//input[contains(@id,'form-') and contains(@value, 'enabled')]";
  String enableRadioButtonOption = "enabled";
  String disableRadioButtonOption = "disabled";
  
  WebElement enableRadioButton = webdriver1.findElement(By.name(enableRadioButtonOption));
  enableRadioButton.click();
  </code></pre>