Finding total number of rows in "HTML table" or inside "div Element"

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
uniadv
Junior Coder
Posts: 29
Joined: Tue Aug 04, 2020 2:16 am

Finding total number of rows in "HTML table" or inside "div Element"

Post by uniadv » Thu Aug 13, 2020 8:52 am

Hi Team,

I'm making a project for myself for gathering the data for each row in the Table and another inside the particular div Element. The number of rows in the table varies from 5 to 30. Similarly for the div, it also varies from 10 to 25.

Whenever i run the code for table, if the value of "n" set to 25 and row exists only upto 10 then the code returning the variable value either "null" or the duplicate value of last existing row (row 10) for the variable "variable11" to "variable24".

Same case happened to the div element also. Here is the code which i'm running to get data.

For "n" number of row in a table

Code: Select all

let>n=1
Repeat>n
  ChromeFindElements>s1,xpath,/html/body/div[1]/div[2]/table/tbody/tr[%n%],strElement
  ChromeGetElementData>s1,strElement_1,text,variable%n%
Until>n=25


For "k" number of element inside a div

Code: Select all

let>k=1
Repeat>k
  ChromeFindElements>s1,xpath,/html/body/div[1]/div[3]/div[%k%],strElement
  ChromeGetElementData>s1,strElement_1,text,variable%k%
Until>k=13
I was wondering if is there any way to find out the total number of row exist in the table so we can set it to the loop limit. Similarly to find out total number of element inside the div, so loop limit can be set accordingly.

Regards
Ushahra

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Finding total number of rows in "HTML table" or inside "div Element"

Post by Marcus Tettmar » Thu Aug 13, 2020 11:40 am

Yes, first get ALL the divs and the array returned will have array_count:

ChromeFindElements>s1,xpath,/html/body/div[1]/div[3]/div,allDivs

Then loop until allDivs_count
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
uniadv
Junior Coder
Posts: 29
Joined: Tue Aug 04, 2020 2:16 am

Re: Finding total number of rows in "HTML table" or inside "div Element"

Post by uniadv » Thu Aug 13, 2020 1:34 pm

Thank you Marcus Tettmar, :D
Now i am able to check how many div or rows present in the table. I know its very basic thing, even i looked this solution inside the Knowledge Base earlier but didn't get any success. But thank you again for helping me out.❤️❤️❤️

Regards
Ushahra

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts