Counting the number of rows(tr) in a table(html) in a website using selenium in VBA

Gautamsunil

New Member
Joined
Apr 19, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi all
I am extracting data of individual student from an institute's website into excel spreadsheet for further manipulation. Though the number of questions in the website are same for all, number of answers differ from one student to another depending upon the number questions he answered. Because of this reason, for the same topic, one student has 5 rows in the table and the other has 7 rows in the same table. I am guessing counting the number of rows in that particular table in the website and then applying if else condition will solve the issue. How can I count the number of rows in a table in a website?
I have tried few codes I found around but ran into problem every single time.
I am using selenium basic to allow extraction through chrome. I have done same thing through Internet Explorer without having any issues.
Any help would be much appreciated as I have spent hours trying to solve this.
Thanks in advance.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this:
VBA Code:
    Dim theTable As WebElement
    '...... your code to get the table
    Debug.Print theTable.FindElementsByTag("TR").Count
 
Upvote 0
Solution
John,​
as a web table as a rows collection so you can directly extract {table object}.rows.length …​
 
Upvote 0
Marc, the rows property isn't available for me. These are the only properties available:
1620144708028.png
 
Upvote 0

Ok I was thinking of DOM under IE but it not exists under selenium, so weird …​
 
Upvote 0
Yes, it's odd that the Selenium library has only one generic class (WebElement), whereas the MS HTML library has a specific class for many HTML elements.
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top