(Solved) – SeleniumBasic VBA Fastest Loop of WebElements using a WebElement method

(solved)-–-seleniumbasic-vba-fastest-loop-of-webelements-using-a-webelement-method

I’m noticing a rather long time for an operation to complete.

I’m using the latest SeleniumBasic for VBA to extract data from a table using a ChromeDriver.
(https://github.com/florentbr/SeleniumBasic)

I’m retrieving WebElements and looping through them to get the text value.

I’m assigning the text value to an array of type String.

This operation takes quite a long time when I have a large array (1000’s of WebElement objects).

Question – What is the fastest way to get all the text values?

Here is my HTML

Name Time Number Rate Other Final
Name Here 123.000 5 8% 20 300.00

Each table row has 6 data points, specified by the td tag. I’ve cut the snippet to only 1 table row but just imagine having 100 table rows.

VBA Code

Dim table As WebElement, tableElements As WebElements, tableData() As String, Element
Dim tableIndex As Integer, tableDataCount As Integer

'Get the table
Set table = bot.FindElementByXPath("//*[@id=""Tables_Table_0""]")

'Get the  elements
Set tableElements = table.FindElementsByTag("td")

'Assign array size to variable to use later on during loops
tableDataCount = tableElements.Count

'Assign array size            
ReDim tableData(tableDataCount)

'Loop index counter       
tableIndex = 1

'PROBLEM HERE - TAKES TOO LONG WHEN I HAVE A BUNCH OF ROWS IN MY TABLE
'Loop each element and get the Text value            
For Each Element In tableElements
    tableData(tableIndex) = Element.text '
    tableIndex = tableIndex   1
Next Element

Leave a Reply

Your email address will not be published. Required fields are marked *