CheckBox & Radio Button Operations in selenium C#



CheckBox & Radio Button Operations in selenium C#

CheckBox & Radio Button Operations in selenium C# are easy to perform and most of the times the simple ID attributes work fine for both of these. But selection and d-selection is not the only thing we want with Check Boxes and Radio Buttons. We might like to check that if the Check Box is already checked or if the Radio Button is selected by default or anything. Check Boxes and Radio Button deals exactly the same way and you can perform below mentioned operations on either of them.

 

Different Selection Method

 

By ID

If ID is given for the Radio Button/CheckBox and you just want to click on it irrespective of it’s value, then the command will be like this:

 

With Selected

If your choice is based on the pre-selection of the Radio Button/Check Box and you just need to select the deselected Radio Button/Check Box. Assume there are two Radio Buttons/Check Boxes, one is selected by default and you want to select the other one for your test. With IsSelected statement, you can get to know that the element is selected or not.

Note: Name is always same for the same group of Radio Buttons/Check Boxes but their Values are different. So if you find the element with the name attribute then it means that it may contain more than one element, hence we need to use FindElements method and store the list of WebElements.

With Value

You can even select Radio Buttons/Check Boxes with their Values.

// Find the checkbox or radio button element by Name
IList <IWebElement> oCheckBox = driver.FindElements(By.Name("ttCheck"));
// This will tell you the number of checkboxes are present
int Size = oCheckBox.Count;
// Start the loop from first checkbox to last checkboxe
for (int i = 0; i < Size; i++)
{
// Store the checkbox name to the string variable, using 'Value' attribute
String Value = oCheckBox.ElementAt(i).GetAttribute("value");
// Select the checkbox it the value of the checkbox is same what you are looking for
if (Value.Equals("techtutorialz"))
{
oCheckBox.ElementAt(i).Click();
// This will take the execution out of for loop
break;
}
}
Tags:
Leave a comment

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

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!

https://bridgejunks.com/ https://crownmakesense.com/ https://brithaniabookjudges.com/ https://hughesroyality.com/ https://rhythmholic.com/ https://bandar89.simnasfikpunhas.com/ https://www.100calshop.co.il/products/thailand/ https://myasociados.com/ https://solyser.com/ http://konfidence.cz/ https://muscadinepdx.com/ https://bandar89.parajesandinos.com.ve/ https://goremekoop.com/ https://oncoswisscenter.com/ https://www.turunclifehotel.com/bandar89/ https://www.houseofproducts.biz/ https://taimoormphotography.com/
BIJI18 BIJI18 BIJI18