Unable to select check with locators please suggest

0 votes

Unable to select checkbox on webpage with locators (Xpath, CSS Selector, Name, ID)

I am using Selenium C# with specflow framework.

Please suggest a C# script to handle checkbox.

Jul 22, 2020 in Selenium by anonymous
• 120 points
106 views

1 answer to this question.

0 votes

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!

answered Jul 22, 2020 by Niroj
• 82,680 points

Related Questions In Selenium

0 votes
1 answer

Need to select an IFrame with selenium (python)

Well for me, something like this worked. ...READ MORE

answered May 3, 2018 in Selenium by sniffy_god
• 780 points
3,288 views
0 votes
1 answer

Selenium with pyvirtualdisplay unable to locate element

If there is some dynamic content on ...READ MORE

answered Sep 14, 2018 in Selenium by Martin
• 4,340 points
790 views
0 votes
1 answer

How to check if an image is displayed on web page while working with Selenium WebDriver?

I've come across a similar situation before, where the image ...READ MORE

answered May 10, 2019 in Selenium by Surya
• 970 points
5,066 views
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
4,912 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,010 points
5,708 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
3,485 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,010 points
4,197 views
0 votes
1 answer

I am not able to generate extent report with screenshot in selenium cucumber java .. Please help me out

Hello @kanikahans, You need to define Extent Report ...READ MORE

answered Aug 23, 2020 in Selenium by Niroj
• 82,680 points
1,720 views
0 votes
2 answers

how to select text by span class

Do you just want to select the ...READ MORE

answered Feb 27, 2020 in Selenium by Etl
• 160 points
673 views