nastyJ
08-24-2016, 08:45 AM
Hello all,
I am trying to select a value in a dropdown list I have on an intranet webpage.
The Html code of the dropdown list is as follows:
<SELECT name="findby" tabIndex="1" class="selectCode" onchange="changeSearchBy();document.filteringForm.criterion.focus();return true;" >
<OPTION selected value=Name>Name</OPTION>
<OPTION value=RICOS>Ricos</OPTION>
<OPTION value=SGC>SGC</OPTION>
<OPTION value=DIG>DIG</OPTION>
<OPTIONvalue=RMC>RMC</OPTION>
<OPTION value=REUTERS>REUTERS</OPTION>
</SELECT]>
Now my code is as follows:
Sub navigateGCE()
Dim ie As New InternetExplorer
Dim IEDoc As HTMLDocument
Dim htmlSelectElem As Variant
Dim elementHtml As Object
ie.Visible = True
'
ie.navigate "MY INTRANET WEBPAGE"
Do While ie.Busy Or Not ie.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Set IEDoc = ie.document
Set htmlSelectElem = IEDoc.getElementsByTagName("findby")
htmlSelectElem.selectedIndex = 2
IEDoc.parentWindow.execScript "changeSearchBy()", "JavaScript"
Set ie = Nothing
Set IEDoc = Nothing
End Sub
It is to be noted that I have declared htmlSelectElem as Variant, using the debugger I see the type of this object is DispHTMLElementCollection.
When I execute the code I have :
Run time error 438, Object doesn't support this property or method
I have tried to use getElementsByName instead but it doesn't work.
Do you know how I can fix this?
Many thanks
I am trying to select a value in a dropdown list I have on an intranet webpage.
The Html code of the dropdown list is as follows:
<SELECT name="findby" tabIndex="1" class="selectCode" onchange="changeSearchBy();document.filteringForm.criterion.focus();return true;" >
<OPTION selected value=Name>Name</OPTION>
<OPTION value=RICOS>Ricos</OPTION>
<OPTION value=SGC>SGC</OPTION>
<OPTION value=DIG>DIG</OPTION>
<OPTIONvalue=RMC>RMC</OPTION>
<OPTION value=REUTERS>REUTERS</OPTION>
</SELECT]>
Now my code is as follows:
Sub navigateGCE()
Dim ie As New InternetExplorer
Dim IEDoc As HTMLDocument
Dim htmlSelectElem As Variant
Dim elementHtml As Object
ie.Visible = True
'
ie.navigate "MY INTRANET WEBPAGE"
Do While ie.Busy Or Not ie.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Set IEDoc = ie.document
Set htmlSelectElem = IEDoc.getElementsByTagName("findby")
htmlSelectElem.selectedIndex = 2
IEDoc.parentWindow.execScript "changeSearchBy()", "JavaScript"
Set ie = Nothing
Set IEDoc = Nothing
End Sub
It is to be noted that I have declared htmlSelectElem as Variant, using the debugger I see the type of this object is DispHTMLElementCollection.
When I execute the code I have :
Run time error 438, Object doesn't support this property or method
I have tried to use getElementsByName instead but it doesn't work.
Do you know how I can fix this?
Many thanks