Search code examples
c#visual-studiogeckogeckofx

Button click not working in GeckoFX (C#)


I have some button on page, click command not navigate page.

Debug console writes "IsWindowModal" Any ideas to solve this? Thanks

GeckoElementCollection link2 = webBrowser1.Document.GetElementsByTagName("input");
foreach (GeckoHtmlElement item in link2)
{
    string aux = item.GetAttribute("onclick");
    if (aux != null && aux != "" && aux.Contains("form1"))
    {
          item.Click();
     }
}

Solution

  • You can trigger the 'onclick' event rather than trying to click programmatically.

        string aux = item.GetAttribute("onclick");
        if (aux != null && aux != "" && aux.Contains("form1"))
        {
              DomEventArgs ev = browser.Document.CreateEvent("MouseEvent");
              Event webEvent = new Event(browser.Window.DomWindow, ev.DomEvent as nsISupports);
              webEvent.InitEvent("click", true, false);
              item.DispatchEvent(ev);
         }