0

I am pretty new to this, and I found a way to count the number of rows in the table, my problem is that my code only counts the "visible" rows and not the rows of the table that are out of the screen.

int rowcount = customMethods.driver.FindElement(By.XPath("/html[1]/body[1]/div[3]/div[1]/div[1]/div[1]/div[2]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/table[1]/tbody[1]")).FindElements(By.TagName("tr")).Count();

This piece of code returns me an amount of 39 rows, but there are 44, the exceed rows are not being visible at the time of the count.

Any help?

Hamid
  • 612
  • 1
  • 8
  • 20
  • 2
    It would be awesome if you could provide a [mcve]. – mjwills Nov 30 '18 at 22:11
  • When you verify the xpath expression in Chrome (see my duplicate), how many rows does it return there? – mjwills Nov 30 '18 at 22:12
  • It is weird but when I examine with chropath the HTML also changes dynamically according to what is being shown in screen. Sadly It is very hard for me to do a minimal complete and verifiable example since I do not have the skills to do so. Thanks for your comments and info though. – Mauricio Figueroa Dec 03 '18 at 07:51

1 Answers1

0
  • You are using absolute xpath which is not acceptable in Automation, as it will break very often. use relative xpath. Something like //table[@id='']/tbody/tr or //table[@class='']/tbody/tr/. Please not you don't have to keep id and class empty you need to put according to your html

  • Other thing is you have used tbody[1] which means your table has two tbody if so remaining 5 rows belongs to other tbody To tix this you can do just use tbody

This might give you all the rows or may be more than 44

int rowcount = customMethods.driver.FindElements(By.XPath("/html[1]/body[1]/div[3]/div[1]/div[1]/div[1]/div[2]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/table[1]/tbody/tr")).Count();

However your xpath Should be like this

int rowcount = customMethods.driver.FindElements(By.XPath("//table[@id='']/tbody/tr")).Count();
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137