HTML:
<tr>
   <td class="formtext" colspan="3">
   <span class="required">*</span>
     Are you?
   </td>
   <td class="formtext" colspan="3">
   <input type="radio" value="M">
     Male
   <input type="radio" value="F">
     Female
   </td>
</tr>
Python:
browser.find_elements_by_xpath('//td[contains(text(),"Are you?")]')[0].find_elements_by_xpath('./following::td[contains(text(),"Male")]//preceding-sibling::input')[0].click() 
My current solution is working [0].click() =  Male, [1].click() =  "Female"
Question:
Instead of using [0] and [1], how to set up so that if text() == "Male" the input before this text will be clicked, so this function will work based on TEXT
P.S. Please do not suggest using value (M/F), I need to make it work based on TEXT
I'm looking for something like this:
Male will be clicked
browser.find_elements_by_xpath('//td[contains(text(),"Are you?")]')[0].find_elements_by_xpath('./following::td[contains(text(),"Male")]//preceding-sibling::input')[0].click()
Female will be clicked
browser.find_elements_by_xpath('//td[contains(text(),"Are you?")]')[0].find_elements_by_xpath('./following::td[contains(text(),"Female")]//preceding-sibling::input')[0].click()
 
     
    