I want to be able to select a radio button based on User input. This radio button has multiple options with the same name.
<th class="radio">
<td>
<label for="form-1-input-3">
<input id="form-1-input-3" type="radio" checked="" value="true" name="enabled">
Enabled
</label>
<label for="form-1-input-4">
<input id="form-1-input-4" type="radio" value="false" name="enabled">
Disabled
</label>
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.
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?
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();
idvalue of the two radio buttons are different then why can't you go for Id. Is there any specific reason?