C#- Selenium Webdriver, Not able to select radiobutton as a label is displayed over it -
i new selenium webdriver , using c# write script. have field gender having male , female option, these options radio buttons displayed labels.
i tried million ways have 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 above. html gender fields looks this:
<li class="radiobutton-yesno ui-buttonset"> <span class="label"> gender <span class="help-icon" data-title="your gender factor in determining 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 field on page appears this:enter image description here
the <input>
type being hidden via css/js rules. can't click on - selenium doesn't let user can't.
the @value
attribute belongs radiobutton <input>
s using in selector won't work, since entire element hidden.
instead, use <label>
or <span>
under label , match it's text:
//label/span[text()='female']
//label/span[text()='male']
ps: bit worrying wrt nature of question:
"your gender factor in determining cost."
Comments
Post a Comment