Webpage Automation (Selecting option from combobox)

sohan0174

New Member
Joined
Dec 5, 2015
Messages
7
I am trying to fill in the form of this webpage "https://login.yahoo.com/account/cre...n-US&done=https://www.yahoo.com&specId=yidReg" with the help of excel vba.

Everything is working fine, except I am failing to choose option from combobox, where i need to choose 'country code'.
ID of the combobox= "
country-code-lbl-aria"

I have tried this code:

Code:
Sub iepart2()


Dim ie As Object
'
Set ie = CreateObject("internetexplorer.application")


With ie
    .Visible = True
    .navigate "https://login.yahoo.com/account/create?src=fpctx&intl=us&lang=en-US&done=https%3A%2F%2Fwww.yahoo.com&specId=yidReg"


Do While .busy
    DoEvents
Loop


Do While .readystate <> 4
    DoEvents
Loop

Set country = ie.document.getElementById("[FONT=Consolas]country-code-lbl-aria[/FONT]")
For i = 1 To country.Option.Length
    If country.Options(i).Text = "Albania (+355)" Then
        country.selectedIndex = i
        Exit For
    End If
Next i
End With
End Sub
It shows this error:


Run-time error 438
Object doesn't support this property or method

on this line- For i = 1 To country.Option.Length

I did change code for the combobox:
Code:
Set HTML = ie.document
Dim drp As HTMLFormElement
Set drp = HTML.getElementById("country-code-lbl-aria")
Dim x As Long
x = HTML.forms.Length
drp.selectedIndex = 5

It shows this error:
Run-time error 438
Object doesn't support this property or method

on this line- drp.selectedIndex = 5

Thanks in advance, Anyone wanting to help, is highly appreciated :)
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
That's not the name of the element; it's the name of the attached label. Also, you'll have to check for the right text and somehow invoke the change() event on the element. This gets you nearer although I'm sure Yahoo! will take a dim view of trying to automate their account creation page:

Code:
Sub iepart2()

Dim ie As Object

Set ie = CreateObject("internetexplorer.application")
With ie
    .Visible = True
    .navigate "https://login.yahoo.com/account/create?src=fpctx&intl=us&lang=en-US&done=https%3A%2F%2Fwww.yahoo.com&specId=yidReg"
    Do While .busy
        DoEvents
    Loop

    Do While .readystate <> 4
        DoEvents
    Loop

    Set country = ie.document.getElementsByName("shortCountryCode")(0)
    For i = 0 To country.Options.Length - 1
        If country.Options(i).Text = "Albania " & ChrW(8234) & "(+355)" & ChrW(8236) Then
            country.Options(i).Selected = True
            Exit For
        End If
    Next i
End With

End Sub

WBD
 
Upvote 0
That's not the name of the element; it's the name of the attached label. Also, you'll have to check for the right text and somehow invoke the change() event on the element. This gets you nearer although I'm sure Yahoo! will take a dim view of trying to automate their account creation page:

Code:
Sub iepart2()

Dim ie As Object

Set ie = CreateObject("internetexplorer.application")
With ie
    .Visible = True
    .navigate "https://login.yahoo.com/account/create?src=fpctx&intl=us&lang=en-US&done=https%3A%2F%2Fwww.yahoo.com&specId=yidReg"
    Do While .busy
        DoEvents
    Loop

    Do While .readystate <> 4
        DoEvents
    Loop

    Set country = ie.document.getElementsByName("shortCountryCode")(0)
    For i = 0 To country.Options.Length - 1
        If country.Options(i).Text = "Albania " & ChrW(8234) & "(+355)" & ChrW(8236) Then
            country.Options(i).Selected = True
            Exit For
        End If
    Next i
End With

End Sub

WBD

Thank you very much, your code worked :)
But I am a newbie, SO facing some difficulties to understand.
In this line:
Code:
If country.Options(i).Text = "Bangladesh " & ChrW(8234) & "(+880)" & ChrW(8236) Then
What does,ChrW(8234) & ChrW(8236) means ! Why to add this ?
Thank you :)
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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