'Selecting and clicking an HTML option via automation using ie.DOM in VB

I'm unable to select an option and click it programmatically vai ie.DOM. Here's what the HTML looks like with the options and the onchange javascript call: code behind dropbox

And here's what the dropdown looks like: Select Report

Here's what I tried that doesn't seem to have any effect on the page

Set ddl = ie.Document.getElementById("ddlReports")
    For Each itm In ddl.getelementsbytagname("option")
        If itm.Value = "12" Then itm.SELECTED = True: Exit For
    Next itm
    itm.Click

I've also tried this but it just clears the page and returns a 0.

ie.Navigate "javascript:setTimeout('__doPostBack(\'ddlReports\',\'\')', 0)"

It's supposed to reveal a button that allows me to retrieve the report.



Solution 1:[1]

Turns out that I needed to submit the form after selecting an option in the dropdown. Here's the code that worked.

Set ddl = ie.Document.getElementById("ddlReports")
For Each itm In ddl.getelementsbytagname("option")
    If itm.Value = "12" Then itm.SELECTED = True: Exit For
Next itm
ie.Document.getElementById("frmAshleyExtracts").Submit

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 IrogSinta