-
Select from Drop down list in Internet Page
Hi all,
PROBLEM
I am trying to select an option within a dropdown list in internet explorer but cannot seem to access the 'select' tagname with all syntax
SOURCE CODE OF INTERNET PAGE
<select id = "selectlist" name = "selectlist" class = "c23_normalText">
<option value = "1" selected>This is Option 1 </option>
<option value = "2" selected>This is Option 2 </option>
</select>
WHAT I TRIED SO FAR
I have tried the following syntax to select Option 1 but to no avail:
~ "With appIE
.document.forms.Item("selectlist").Value = "1"
(I keep getting the error "Runtime error '91'. Object variable or With block variable not set)
~ Also tried "getelementsbytagname("selectlist") but also could not access
Hope someone can help on this! Thanks!
-
Assuming that the HTML form in which the select element resides is the first form on the web page, i.e. forms(0), try:
.document.forms(0).Item("selectlist").Value = "1"
-
Follow up on Select from Dropdown
Hi,
I received the following message when I typed in the code you recommended:
"invalid or unqualified reference"
So I added 'With appIE.....End With" before and after the line --> the error was gone.
BUT I received another error "object variable or with block variable not set"
Can someone advise on this? Thanks!
-
Follow up on select fr dropdown list in internet
HI everyone, this is the whole code which I am using when I tried to select the option value and a few points which I considered - hope it helps give some brilliant ideas to solve my problem!!
- The macro below will print on the main worksheet the names of all the option value and select list
- BUT it works on the below website & NOT my company intranet website
- I noticed my company website uses java scripting but I am not sure which info I shld pick out to share here to get some solutions. If you want to look at any part, pls let me know & i will type it out line by line here...just wants to get this going!
- Also, I have been seekin help and understand perhaps where the dropdown list sits in will matter --> i.e. which forms but when I use '.document.forms(0).item("selectlist").value="1", I keep getting error like "runtime error 91" & "object variable or with block variable not set"
- Hope someone can give some ideas on this!
- I am on the verge of using sendkeys which I'm sure will be loads of problems given e instability of sendkeys..
- Hope someone can help on this!
Sub SelectFromDropDownList()
Dim appIE As InternetExplorer, btnSelect As MSHTML.HTMLSelectElement
Dim btnOption As MSHTML.HTMLOptionElement, ElementCol As MSHTML.IHTMLElementCollection
Dim ElementCol1 As MSHTML.IHTMLElementCollection
Application.ScreenUpdating = False
Set appIE = New InternetExplorer
With appIE
.Visible = True
.navigate "http://app.lta.gov.sg/home_list.asp"
End With
Do While appIE.Busy Or appIE.Readystate <> Readystate_Complete
DoEvents
Loop
' In LTA job search webpage, go to the drop down list "Select by Qualification" and make a selection.
'========================================================================== =================================
Set ElementCol = appIE.Document.getElementsByTagName("Select")
For Each btnSelect In ElementCol
If btnSelect.Name = "Min_Qualification" Then
'Within the "Select" element named "Min_Qualification", group all the "Option" element in "ElementCol1"
Set ElementCol1 = btnSelect.getElementsByTagName("Option")
For Each btnOption In ElementCol1
' There are 5 options to select from: "" i.e. the null option,
' "Degree",
' "Diploma",
' "Post-Graduation" and
' "GCE-A/N/O/ITE"
' The webpage's default choice is ""
If btnOption.Value = "GCE-A/N/O/ITE" Then 'Select the option "GCE-A/N/O/ITE"
btnOption.Selected = True
End If
Next btnOption
End If
Next btnSelect
'========================================================================== =================================
Application.ScreenUpdating = True
End Sub
Sub GetOptionValue()
' This subroutine prints out the option value of each of the "Select" element onto the second worksheet
' The first row contains the ID of each "Select" element, the columns under the first row contains the
' respective option values and the text associated to each option value
Dim appIE As InternetExplorer, btnSelect As MSHTML.HTMLSelectElement
Dim btnOption As MSHTML.HTMLOptionElement, ElementCol As MSHTML.IHTMLElementCollection
Dim ElementCol1 As MSHTML.IHTMLElementCollection, i As Long, j As Long, URL As String
Application.ScreenUpdating = False
URL = "http://app.lta.gov.sg/home_application1.asp?SERIALNO=gp91rf8z34xv62es42m64lth039d7rn80l91rp9yxqxd hiwvww&source="
Set appIE = New InternetExplorer
With appIE
.Visible = True: .navigate URL
End With
Do While appIE.Busy Or appIE.Readystate <> Readystate_Complete
DoEvents
Loop
' Get the option values for each of the "Select" element in the webpage
'========================================================================== =================================
j = 1
Set ElementCol = appIE.Document.getElementsByTagName("Select")
For Each btnSelect In ElementCol
i = 0
Worksheets(2).Cells(1, j) = btnSelect.Name
Set ElementCol1 = btnSelect.getElementsByTagName("Option")
For Each btnOption In ElementCol1
i = i + 1
Worksheets(2).Cells(i + 1, j) = btnOption.Value
Worksheets(2).Cells(i + 1, j + 1) = btnOption.Text
Next btnOption
j = j + 2
Next btnSelect
'========================================================================== =================================
Application.ScreenUpdating = True
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules