Reputation: 271
I am trying to fetch associate value of radio button.The HTML code is like
<td>
<input id="ctl00_mainContent_rdbList_0" type="radio" checked="checked" value="1" name="ctl00$mainContent$rdbList"/>
<label for="ctl00_mainContent_rdbList_0">Employment History</label>
</td>
i am provideing the xpath of radio button that is .//*[@id='ctl00_mainContent_rdbList_0']
and want to fetch the value Employment History
please help me to find out the best solution with selenium web driver 2.
Upvotes: 2
Views: 2414
Reputation: 16201
Easiest way is to use xpath and walk through the nodes. After finding the intended radio you can walk to the parent and simply point to the label
//input[@id='ctl00_mainContent_rdbList_0']/../label
Or, in this case you have the for attribute in label tag that can also be used to find the label for the same radio.
A cssSelector would be easier for that
[for='ctl00_mainContent_rdbList_0']
Upvotes: 2