Jin Jin - 1 year ago 212
C# Question

Selecting checkbox in a table using selenium

I'm trying to check a Checkbox in a table, it actually able to locate the Checkbox but it does not check/click the checkbox. The selectCheckbox.Click() is not working, can somebody explain to me why it's not checking/clicking the checkbox? thanks :)

my code is like this:

IWebElement table = WebBrowser.Current.FindElement(By.TagName("tbody"));

ReadOnlyCollection<IWebElement> allRows = table.FindElements(By.TagName("tr"));

for (int z = 0; z < allRows.Count; z++)
ReadOnlyCollection<IWebElement> cells = allRows[z].FindElements(By.TagName("td"));

for (int y = 0; y < cells.Count; y++)
var value = allRows[z].FindElements(By.TagName("td"))[y].Text;

if (value.Equals(tenant))
var selectCheckbox = allRows[z].FindElements(By.TagName("td"))[y - 1];

Answer Source

You are finding the td tag and trying to click on it. Try changing the code as shown below to find the input tag (Assuming that there is only one input tag in the required td)


var selectCheckbox = allRows[z].FindElements(By.TagName("td"))[y - 1];


var selectCheckbox = allRows[z].FindElements(By.TagName("input"))[y - 1].FindElement(By.TagName("input"));

Hope this helps you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download