I am new to Selenium webdriver and i am using C# to write the script. I have a field Gender having Male and Female option, these options are actually radio buttons but are displayed like labels.
I tried million ways to have it selected:
- driver.FindElement(By.CssSelector("[value='Female']")).Click();
- driver.FindElement(By.XPath("//input[contains(@value,'Male']")).Click();
- driver.FindElement(By.CssSelector("input[type='radio'][value='Male']")).Click();
- driver.FindElement (By.XPath ("//input[@value='Female']")).Click ();
But NONE worked from above. The html for the Gender fields looks like this:
<li class="radiobutton-yesno ui-buttonset">
<span class="label">
Gender
<span class="help-icon" data-title="Your gender is a factor in determining your cost.">
</span>
</span>
<input type="radio" id="genderNo_1" name="gender_1" value="Male" class="reqCntrl ui-helper-hidden-accessible">
<label for="genderNo_1" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button">
<span class="ui-button-text">Male</span>
</label>
<input type="radio" id="genderYes_1" name="gender_1" value="Female" class="ui-helper-hidden-accessible">
<label for="genderYes_1" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right" role="button">
<span class="ui-button-text">Female</span>
</label>
</li>
and the field on page appears like this:enter image description here