Search code examples
c#eventsgeckofx

GeckoFX - alternative of WebBrowser control's "RaiseEvent" or "InvokeMember"


In Microsoft webbrowser control it is possible to do something like that:

webBrowser1.Document .GetElementsByTagName("select")[4] .RaiseEvent("onchange");

which will programmatically raise the event on the webpage.

Is it possible to do so with GeckoFX? I did not find any method that would work this way with HTML elements (select for example)

Cheers


Solution

  • After a couple of days worth of searching, I have found out how this works

    First, create the 'name' of the event

    Then, create the event itself

    Then initialize this event

    Finally, dispatch this event on the target. For example:

    nsAStringBase changeEvent = (nsAStringBase)new nsAString("change");
    var ev = browser.Document.CreateEvent("HTMLEvents");
    ev.DomEvent.InitEvent(changeEvent, false, false);
    myElement.GetEventTarget().DispatchEvent(ev);
    

    Works like a charm, hope this will be useful for someone in the future.

    Bartosz