I log into a website and I'm attempting to select all items in a list.
The login works, but the items are not being highlighted or selected prior to submitting.
Sub BrowseToSite() 'Login to site
'set ie = internetexplorer for reference
Dim ie As New SHDocVw.InternetExplorer
Dim htmldoc As MSHTML.HTMLDocument
Dim htmlinput As MSHTML.IHTMLElement
Dim htmlbuttons As MSHTML.IHTMLElementCollection
Dim objIE As Object
'see window and navigate to website (HOURLY VOLUME ENERGY COMPOSITION - HVEC)
ie.Visible = True
ie.navigate "www.website.com"
'wait for brower to load
Do While ie.readyState <> READYSTATE_COMPLETE
Loop
'Enters username and password
Set htmldoc = ie.document
Set htmlinput = htmldoc.getElementById("USER")
htmlinput.Value = "LoginUsername"
Set htmlinput = htmldoc.getElementById("PASSWORD")
htmlinput.Value = "Password1"
'finds form > submit button (under class = "LoginSubmit")
htmldoc.forms(0).submit
'select all Locations
ie.document.getElementsByName("ctl00$contentPlaceHolder$ctl00$availableLocations").Value = "1297"
ie.document.getElementsByName("ctl00$contentPlaceHolder$ctl00$availableLocations").Value = "3216"
ie.document.getElementsByName("ctl00$contentPlaceHolder$ctl00$availableLocations").Value = "3135"
objIE.document.getElementsByName("ctl00$contentPlaceHolder$ctl00$availableLocations")(0).Click
End Sub
Here is the HTML Code:
<tr>
<td class="fieldLabel">Location:</td>
<td class="fieldData" colspan="3">
<select size="12" name="ctl00$contentPlaceHolder$ctl00$availableLocations" multiple="multiple" id="contentPlaceHolder_ctl00_availableLocations" tabindex="8" class="fullWidth" onFocus="resetList('operatorList');">
<option value="1297">1297 - Test1</option>
<option value="3216">3216 - Test2</option>
<option value="3135">3135 - Test3</option>