Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top