How to locate radio buttons using the legend within the fieldset in selenium

Viewed 112

Trying to find a way to locate the radio buttons under a specific fiedlset legend. The webpage has 18 fieldsets with the only difference being the legend

<fieldset class="radio-group radio-standard">
   <legend>Legend example 1</legend>
   <ul class="rg-list">
      <li class="rg-item"><label class="radio-button"><input class="rb-input" type="radio" name="feature-12-0" value="none" checked=""><span aria-hidden="true" class="rb-design"></span><span class="rb-label">None</span></label></li>
      <li class="rg-item"><label class="radio-button"><input class="rb-input" type="radio" name="feature-12-0" value="RO"><span aria-hidden="true" class="rb-design"></span><span class="rb-label">Read Only</span></label></li>
      <li class="rg-item"><label class="radio-button"><input class="rb-input" type="radio" name="feature-12-0" value="RW"><span aria-hidden="true" class="rb-design"></span><span class="rb-label">Read/Write</span></label></li>
   </ul>
</fieldset>

I can locate the legend using this xpath: ("//legend[contains(.,'Legend example 1')]

Locating the "None" radio button using this xpath: //label[contains(.,'None')]/input");

However I'm not too sure how to link the two to get to the radio buttons using the radio values.

Any ideas?

Thank you in advance :)

1 Answers

Try this one:

//legend[.='Legend example 1']/following-sibling::ul//label[.='None']/input
Related