Back2Pavillion | Free Selenium Tutorials | Selenium WebDriver | How to handle radio and checkbox button in Selenium WebDriver?

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.

So let’s begin the Selenium learning journey with your host and dost (friend), Avinash Mishra

 

HTML structure of Radio button

radio and checkbox button

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

radio and checkbox button

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

radio and checkbox button

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

radio and checkbox button

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.

 

Radio and Checkbox button – Web element declaration

We can find radio button by using the following command:

I have shown XPath here, you can replace XPath by either CSS Selector or any other web element locators.

 

How to perform Radio and Checkbox button validation?

Selenium WebDriver API offers three methods to validate radio and checkbox button. Those methods are as follows:

isSelected()

It validates whether radio and checkbox button is selected or not. Its return type is boolean. Hence, it returns either true or false.

isDisplayed()

It validates whether radio and checkbox button is displayed or not. Its return type is also boolean. Hence, it will also display result either true or false.

isEnabled()

It validates whether radio and checkbox button is enabled to select/display or not. Boolean is the return type. Therefore, it displayed results in either true or false.

Here is the sample code where these validations are implemented:

Console Output

radio and checkbox button

About 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.

Check Also

Selenium 3 Inviul Geckodriver

GeckoDriver: FAQs & Set up Guide in Selenium 3 for Latest Firefox

An Older version of Selenium like Webdriver 2.51 is working fine till Mozilla Firefox version …

Leave a Reply

Your email address will not be published. Required fields are marked *