Using VBS to select a value on a dropdownlist in webpage
<p>I'm currently working on on a script to open a website, select a value in a dropdownlist and do a search, I'm having trouble with the selection of a value in the dropdownlist, below is my vbs code:</p>

<pre><code>Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 1
IE.navigate "https://website.com/form.aspx"
Do
    WScript.Sleep 10
Loop While IE.ReadyState &lt;4 And IE.Busy
'Button to access form
Set SLTOI = IE.document.getElementByID("ctl00_m_g_4e7438b0_6aba_44b0_a0a1_f49486f81665_FormControl0_V1_I1_S1_I1_B1")
SLTOI.click
'Dropdownlist element
Set SPCI = IE.document.getElementByID("ctl00_m_g_4e7438b0_6aba_44b0_a0a1_f49486f81665_FormControl0_V1_I1_S2_I2_D7")
For Each opt In SPCI.options
    MsgBox opt.value
    If opt.value = "ION CISCO" Then
        opt.Selected = True
    Else
        opt.Selected = False
    End If
Next
</code></pre>

<p>The source of the dropdownlist is the following (using developers option to inspect the element in IE)</p>

<pre><code>&lt;SELECT tabIndex=0 title="" class="v_utCmzxtdUQZu9e3j_0 n_utCmzxtdUQZu9e3j_0 bb_utCmzxtdUQZu9e3j_0 d3_utCmzxtdUQZu9e3j_0" id=ctl00_m_g_4e7438b0_6aba_44b0_a0a1_f49486f81665_FormControl0_V1_I1_S2_I2_D7 style="DIRECTION: ltr" onfocus="return (DropDownList.OnFocus(this, event));" onblur="return (DropDownList.OnBlur(this, event));" onchange="return (DropDownList.OnChange(this, event));" OriginalId="V1_I1_S2_I2_D7" FormId="ctl00_m_g_4e7438b0_6aba_44b0_a0a1_f49486f81665_FormControl0" ViewDataNode="12" direction="ltr" wrapped="true" ScriptClass="DropDownList"&gt;&lt;OPTION value=""&gt;&lt;/OPTION&gt;&lt;OPTION value="ION CISCO" selected&gt;ION CISCO&lt;/OPTION&gt;&lt;/SELECT&gt;
</code></pre>

<p>The code executes correctly but the value is not selected in the dropdownlist field (added a Msgbox inside the  For to see if the code executed, but it doesnt enter the For at all), if i select a value manually from the list and then try to select another value, the list only has the value i selected previously, unless i click a clear button the list is not populated again, seems that a script is running to populate the list.</p>

<p>Any ideas on how i can make my code work?, have tried to use the "FireEvent("onchange")" after doing a selection but didnt work.</p>

<p>Any help will be appreciated!</p>