0

I'm trying to automate a website, and I have the following piece of code to change the value of a dropdown (select):

private bool ChangeElementSelection(mshtml.IHTMLDocument3 document, string id, string value)
    {

        var el = document.getElementById(id);
        if (el != null)
        {
            log.Write("Setting HTML element " + id + " value to " + value + " (by ID)");
            el.setAttribute("value", value);
            var el3 = (el as IHTMLElement3);
            el3.FireEvent("onchange");
            return true;
        }
        log.Write("Could not find HTML element " + id + " (by ID)");
        return false;
    }

The website I am visiting uses JQuery to catch the "change" event for the select element. It does not expect any parameters. Yet the script is not triggered. Why ?

pixartist
  • 1,137
  • 2
  • 18
  • 40
  • you can also check whether el3 is not null. check el3.FireEvent("onchange",null); you can also try el3.InvokeMember("onchange"); – Kamran Shahid May 27 '14 at 12:54
  • There is no method called InvokeMember, also el3 is not null. The SetAttribute part works fine. – pixartist May 27 '14 at 13:07
  • have u tried el3.FireEvent("onchange",null) ? I was just checking http://social.msdn.microsoft.com/Forums/windows/en-US/02c7a1fc-e9a8-4700-bfb1-33dc4daa388f/controlling-a-website-via-a-webbrowser-control – Kamran Shahid May 27 '14 at 13:08
  • In http://www.itwriting.com/phorum/read.php?3,1507 someone also is adding a dummy event Also check http://help.dottoro.com/ljvtddtm.php I have used mshtml for couple of web crawling applications – Kamran Shahid May 27 '14 at 13:12

0 Answers0