0

I'm using C# Webbrowser to navigate a site and click some links. So When a page loads it's supposed to raise an onclick event for an anchor. Also, using InvokeMethod("click") hasn't ever worked for me.

private void StartGetDetails(HtmlElementCollection links)
    {
        if (csrLinks.Count > 0)
        {
            HtmlElement csr = csrLinks.First();
            System.Threading.Thread.Sleep(1000);
            csr.RaiseEvent("onclick");
            csrLinks.RemoveAt(0);
        }
    }

I'm getting this error at csr.RaiseEvent("onclick"):

Error HRESULT E_FAIL has been returned from a call to a COM component.

Any help would be appreciated, nothing I found googling around seemed helpful.

noseratio
  • 59,932
  • 34
  • 208
  • 486
Darth_Evil
  • 591
  • 1
  • 7
  • 18
  • What is `csrLinks`, why don't you use `links`? Any **real** code to post? – L.B Feb 17 '14 at 18:17
  • Oops, my apologies, csrLinks is a global List. Basically, I have a list of anchors of ids in an html table, I get the links into a list, go in each object, parse and leave. Once I'm back at the list I go into the next link. The code works otherwise and only fails here. – Darth_Evil Feb 17 '14 at 18:22
  • What version of Windows is this? – Dayan Feb 17 '14 at 19:17
  • It's Windows 7, I was using IE11, downgraded to IE9 now. – Darth_Evil Feb 17 '14 at 19:23
  • Are you calling `StartGetDetails` on the *same* thread where the `WebBrowser` was created? I.e., the main UI thread? – noseratio Feb 18 '14 at 08:29
  • Yes, the WebBrowser and all its code are running on the same thread. This program is trying to crawl a ticketing software. I'm writing this mostly event-based. – Darth_Evil Feb 19 '14 at 16:35

1 Answers1

0

It seems to be that I've fixed the problem. The problem was that the HtmlElement I was trying to raise onclick for did not have an onclick method, or was null. However, WebBrowser was instead sending this exception rather than a NullReference exception.

Darth_Evil
  • 591
  • 1
  • 7
  • 18