I want to be able to select a radio button based on user input. This switch has several 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 switch that has visible text, Enabled, and if "disabled" is passed as a string, I should select a switch that has visible text, disabled.
I am having difficulty because the switch name is the same. The code below cannot find an element with an AND operator for Xpath. Has anyone come across this before and 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();
user1886649
source share