Excel VBA: Scroll within a dynamic dropdown list (WebElement) so that options show up

32 views Asked by At

I need to obtain the data from the following website and export to Excel using VBA based on the "Contract Month" filter:

https://www.sgx.com/derivatives/delayed-prices-options?category=iron-ore&cc=FEF

This code works well till "Jul 2024":

Dim ie As New ChromeDriver

    With ie
        .Get "https://www.sgx.com/derivatives/delayed-prices-options?category=iron-ore&cc=FEF"
        .Window.Maximize
        .FindElementByXPath("//button[text()='No thanks']").Click
        .FindElementByXPath("//*[@id='gdpr-banner']/div/button").Click
    End With

        Application.Wait (Now + TimeValue("0:00:2"))
                    
    ie.FindElementByName("show-inactive-strikes").Click
        Application.Wait (Now + TimeValue("0:00:1"))

    ie.FindElementByCss("sgx-input-select.text-strong.col-6.col-xs-4.col-sm-4.col-lg-2.sgx-input").Click

'        'scroll down the option list
        ie.Mouse.moveTo ie.FindElementByCss("[title='Jul 2024']")
        ie.FindElementByCss("[title='Jul 2024']").Click
            Application.Wait (Now + TimeValue("0:00:1"))

However, as the dropdown list seems to show only the first 12 months from now, "Jan 2025" option would not appear unless I scroll down the ScrollBar within the dropdown list.

I tried to execute JavaScript,

ie.ExecuteScript "window.scrollBy({top: 500, left: 0, behavior: 'smooth'});"

but it only scroll the Window and not the ScrollBar within the dropdown list.

Is there any suggestion on what can be done?

Thanks in advance.

0

There are 0 answers