Word/VBA, Chrome, wait for "Sendkeys PageDown"

549 views
Skip to first unread message

Christopher Greaves

unread,
Dec 9, 2021, 4:44:57 PM12/9/21
to Selenium Users
The VBA code below works - I find 538 videos - but I know that sending TWO PgDn commands, and then waiting 2 seconds after each operation is poor programming.
I have searched this forum but cannot see a Selenium driver way to issue the SendKeys and then wait until it is completed.
I am fairly new to Selenium/HTML/CSS/JavaScript, but not new to programming. That is why I am sure this is poor programming.
If anyone knows an simple way to wait I'll be pleased.

I say that this code works because it delivers the results I want; the code is run perhaps once a week, so timing is not critical to me, but in some later project timing could be important.
Thanks.
Chris

Sub test()
    Dim drv As New Selenium.ChromeDriver
    With drv
        Dim strURL As String
        strURL = "https://www.youtube.com/user/WayOutWestx2/videos"
        .Get (strURL)
        .Window.Maximize
    End With
   
    Dim wes As WebElements
    Set wes = drv.FindElementsById("video-title")
    Dim lngWesCount As Long
    While lngWesCount <> wes.Count
        lngWesCount = wes.Count
        drv.SendKeys (drv.Keys.PageDown)
        drv.Wait (2000)
        drv.SendKeys (drv.Keys.PageDown)
        drv.Wait (2000)
        Set wes = drv.FindElementsById("video-title")
        drv.Wait (2000)
    Wend
'    drv.SendKeys (drv.Keyboard.SendKeys("PAGE DOWN"))
    Debug.Print wes.Count & " Videos found"
    Dim we As WebElement
    Dim lng As Long
    For Each we In wes
        lng = lng + 1
        Debug.Print Str(lng) & " " & we.Text & " " & we.Attribute("href")
    Next we
    Stop
End Sub

Reply all
Reply to author
Forward
0 new messages