Hello,
Check Boxes and Radio Button deals exactly the same way and you can perform below-mentioned operations on either of them.
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:
IWebElement radioBtn = driver.FindElement(By.Id("toolsqa"));
radioBtn.Click();
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("tool"));
// 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("toolsqa"))
{
oCheckBox.ElementAt(i).Click();
// This will take the execution out of for loop
break;
}
}
By CssSelector
A simple way of selecting a check-box or radio button is by using its value:
|
IWebElement oCheckBox = driver.FindElement(By.CssSelector("input[value='Tools QA']"));
oCheckBox.Click(); |
|
Hope it helps!!
Thank you! |