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:

  1. driver.findelement(by.cssselector("[value='female']")).click();
  2. driver.findelement(by.xpath("//input[contains(@value,'male']")).click();
  3. driver.findelement(by.cssselector("input[type='radio'][value='male']")).click();
  4. 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:

  1. //label/span[text()='female']
  2. //label/span[text()='male']

ps: bit worrying wrt nature of question:

"your gender factor in determining cost."


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -