The web application we use for tracking field logs is B2W. The field logs are listed in a table wrapped in an auto-scrolling div. I am using vba to get the field log info from that table to store in Access. But it will only retrieve the first 25 rows. I've tried using
driver.ExecuteScript(window.ScrollTo())
but it doesn't work for me. If I scroll, it tells me the elements can no longer be found. If I use FireBug, I can see that the data is there in between the
<span>This would be a field log id number</span>
I am assuming it's not there until I scroll to it. I've been googling but nothing I've tried has worked. My current code is:
Private selDriver as New Selenium.ChromeDriver
'I have also tried using FirefoxDriver (I am using Firefox 46.0.1)
'Same results
Public Sub AppendFieldLogs()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblFieldLogs")
Dim i As Integer
With rs
Dim FLogs As Object, FLog As Object, FLogData As Object
With selDriver
.Get "http://tls-okc-b2w/B2W/FieldLogListing.aspx"
.Wait 600
End With
selDriver.ExecuteScript ("window.scrollTo(0, document.body.scrollHeight);")
For Each FLogs In selDriver.FindElementsByXPath("/html/body/div[1]/div/form/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/table/tbody")
For i = 1 To FLogs.FindElementsByXPath(".//tr").Count
If FLogs.FindElementByXPath(".//tr[" & i & "]").IsPresent Then
Set FLog = FLogs.FindElementByXPath(".//tr[" & i & "]")
If FLog.FindElementByXPath(".//td[2]").Text = "" Then
Exit For
End If
.AddNew
!FieldLogID = FLog.FindElementByXPath(".//td[2]").Text
!FieldLogDate = FLog.FindElementByXPath(".//td[3]").Text
!FieldLogSupervisor = FLog.FindElementByXPath(".//td[4]").Text
!FieldLogStatus = FLog.FindElementByXPath(".//td[6]").Text
!FieldLogJob = FLog.FindElementByXPath(".//td[7]").Text
.Update
.Bookmark = .LastModified
Else
Exit For
End If
Next i
Next FLogs
End With
Set rs = Nothing
Set db = Nothing
selDriver.Quit
DoCmd.OpenTable "tblFieldLogs"
End Sub
This works for the first 25 rows. After that, it quits and doesn't give any errors. It just doesn't fetch the data.
EDIT: Here is a link to my onedrive where I saved some of pages HTML and ASPX code. OneDrive
EDIT: ALMOST solved this myself: I found a way to scroll the additional rows into view with the .scrollIntoView method. I am using an if statement to check if the value of the column = "", if it does, then use
driver.findelementmethodofyourchoice.scrollIntoView
and it works for the most part! It will only grab the first 200 rows, but I can see in the source code for the page that only the first 200 rows are loaded into the table, but as you scroll more, more will load. I just need to figure out how to get that 'more' to load.