Select the drop down option

VICKY2007

New Member
Joined
Mar 12, 2019
Messages
1
Sub mar()


Dim IE As New SHDocVw.InternetExplorer

IE.Visible = True
IE.navigate "http://aicf.in/national-tournament-registration/"

Do While IE.readyState <> 4
Loop

IE.document.getElementById ("national_plr_payments_form")



End Sub


Help me to select the drop down option
I don't know whether I have selected the correct element id.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Re: Help me to select the drop down option

Try this macro. You must set a reference (via Tools -> References in the VBA editor) to MS HTML Object Library.
Code:
Public Sub IE_Dropdown()

    Dim URL As String
    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim dropdown As HTMLSelectElement
    Dim dropdownText As String, dropdownIndex As Long
    
    URL = "http://aicf.in/national-tournament-registration/"
    
    Set IE = New InternetExplorer
    With IE
        .Visible = True
        .navigate URL
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set HTMLdoc = .document
    End With
        
    Set dropdown = HTMLdoc.getElementsByTagName("SELECT")(0)
    dropdownText = "*National RAPID*"
    dropdownIndex = FindSelectOptionIndex(dropdown, dropdownText)
    dropdown.Focus
    dropdown.Click
    dropdown.selectedIndex = dropdownIndex
    dropdown.FireEvent "onchange"

End Sub


Private Function FindSelectOptionIndex(selectElement As HTMLSelectElement, findOptionText As String) As Long

    Dim i As Long
    
    FindSelectOptionIndex = -1
    i = 0
    While i < selectElement.Options.Length And FindSelectOptionIndex = -1
        'Debug.Print i; selectElement.Item(i).Value & " >" & selectElement.Item(i).Text & "<"
        If LCase(selectElement.Item(i).Text) Like LCase(findOptionText) Then FindSelectOptionIndex = i
        i = i + 1
    Wend

End Function
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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