How to handle radio and checkbox button in Selenium WebDriver?

HTML has the various input type in the form of buttons. As for example, Radio and Checkbox button, Submit button, Reset button, etc. Today we are going to discuss working with Radio and Checkbox button in Selenium WebDriver. If we understand the handling of these two buttons thus we can handle other HTML buttons smoothly in Selenium.

HTML structure of Radio button

HTML structure of radio button in above image would be like-

ADA

1

<input type="radio"name="sex"value="1"id="u_0_4"/>

In above HTML code, we observe that there is an input tag and within that tag, developers define radio button as a type. This radio type button has a unique id. Hence we can find this radio button web element by using its id very easily.

HTML structure of Checkbox button

HTML structure of checkbox button in above image would be like-

ADA

1

<input type=checkbox name='DelId'value='3702786'>

Similar to above explanation, there is an input HTML tag with type declaration as Checkbox. Here, we can use its name to find checkbox web element, instead of id as described above.

Note: Name tag is another easily identifiable web element technique after id type.

Console Output

Avinash Mishra

Avinash Mishra is the author of Inviul blog. He is a software engineer and blogger by choice. He loves to write blogs, and apart from blogging, he is interested in documentary film making, listening to music, traveling around the world and philanthropic activities.