1

I am trying to count the rows of the table and below is the HTML: my html

I want to get the total count rows of the table, discarding table header and expanded row. I had tried the code below:

var altrowCount = driver.FindElement(By.Id("resultsRepeaterGrid")).FindElements(By.TagName("tr")).Count;

Now I realized it is counting all the tr. Hoping to get some input from who had experienced this. Thanks!

I had a working protractor script which was

searchResCount = element.all(by.css('#resultsRepeaterGrid tr[class="row"], tr[class="altrow"]'));

Now how do I translate this syntax to c# webdriver language?

2

To translate your protractor script use the same css selector:

int searchResCount = driver.findElements(By.CssSelector("#resultsRepeaterGrid tr[class="row"], tr[class="altrow"]")).Count;
  • what happened was, it counted all tr that can be found in the HTML. What I wanted is to only count the occurrences of the classes 'altrow' and 'row' and maybe add them up. I had a working protractor script which is this: searchResCount = element.all(by.css('#resultsRepeaterGrid tr[class="row"], tr[class="altrow"]')); I am not sure how to translate to C# webdriver language – Marj Jun 17 '16 at 13:09
  • 1
    I'm not sure what is your goal, but if you have working protractor script it should be easy to change it to C# webdriver. Try with the same css selector: driver.findElements(By.CssSelector("#resultsRepeaterGrid tr[class="row"], tr[class="altrow"]")).Count – kotoj Jun 17 '16 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.