0

I have a scenario where i need to find the count of rows in the table. The data on the table keep on loading once I scroll down. I need to write a logic to scroll till all the data loads and then get the count of rows.

One solution I have is to get the page height before scrolling to the bottom and then take the page height and apply the while loop to run the loop until before and after loop is equal. One issue I am facing in this is I am unable to get the page height. Is there a way to the page height?

  • 1
    Does this answer your question? [How to get height of entire document with JavaScript?](https://stackoverflow.com/questions/1145850/how-to-get-height-of-entire-document-with-javascript). Before asking a question in the future, please do a search to see if the question has already been asked and answered. This is a very common issue and the StackOverflow answer was the top result in a simple Google search. – Stephen M Irving May 31 '22 at 16:09
  • Yes i saw this answer but this one is not giving the right answer as when I use below solution by @Agan then I get only a fixed value of 8 which is not the correct value. Also if I use document.body.scrollHeight its giving me 0 value from the code . but when I run this from browser console then I I getting the correct result. How can I get this value from cypress script – Suchit Narayan Jun 01 '22 at 03:05

1 Answers1

1

The simplest way to get correct height is to get all height values found on document, or documentElement, and use the highest one'

var body = document.body,
    html = document.documentElement;

var height = Math.max( body.scrollHeight, 
                       body.offsetHeight, 
                       html.clientHeight,  
                       html.scrollHeight, 
                       html.offsetHeight );

Agan
  • 447
  • 2
  • 12
  • Thanks for the answer but when i use this code in my cypress test every time it gives value 8 which is not the correct value. let me know if I am doing something wrong here – Suchit Narayan Jun 01 '22 at 03:10
  • I solved this here: https://codepen.io/agandurmisevic/pen/YzeagbR for you. I have 3016, and if you change body height - u should see the new height. – Agan Jun 01 '22 at 07:25