Select radio button based on text from datatable in framework | Selenium Python Forum
Sambhav Puri Posted on 26/11/2020


I want to select a radio button based on the name displayed after the radio button, either "No" or "Yes".

The value "No" or "Yes" will be passed dynamically by the user in the datatable of the framework.


Can you suggest how can i click on a particlar radio button dynamically considering following is the piece of html code around the radio button group. Thank you in advance.


   <tbody class="radio_groups_class" id="id_of_table">
           <input type="radio" name="name_of_radio_button_group" checked="checked" value="value_of_radio_NO" class="radio_groups_class">&nbsp;No
           <input type="radio" name="name_of_radio_button_group" value="value_of_radio_YES" class="radio_groups_class">&nbsp;Yes

09914040666 Replied on 08/12/2020


I am not sure if the option for Yes/No is on the radio button, if it than you can make the xpath for the radio button like this : //input[text()='']

Now, as you are saying, Yoes/No will come dynamically from user, than you can make a user defined function which accepts input from user and you can store in a variable and return it. You can use the function made anywhere as per your convenience. Like a snippet code is below which you may refer. 

def attempt(option):
    xpath = "//input[text()='"+option+"']"
    return xpath


Let me know if this solve your issue.

Related Posts